Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.
This repository was archived by the owner on Jul 30, 2020. It is now read-only.

selector? option is not typed properly #71

Closed
@ajsmth

Description

@ajsmth

Looks like this option is implemented with the namespace 'filter' rather than selector, and the typescript definition flags this.

e.g in query-helpers.js:

Relevant code or config:

function queryAllByProp(
  prop,
  container,
  match,
  { filter = n => n, exact = true, collapseWhitespace, trim, normalizer } = {},
) { ... }

What you did:

I tried using the selector option for one of my custom queries

What happened:

Reproduction:

Example:

test.only('selector? bug', () => {
  const { baseElement, debug } = ntlRender(
    <Text accessibilityLabel="Hi" accessibilityStates={['disabled']}>
      Hi
    </Text>
  );

  // always finds because selector is not recognized as a filter
  const alwaysFinds = getByLabelText(baseElement, 'Hi', {
    selector: ({ props }) => props.acessibilityStates.includes('selected'),
  });

  debug(alwaysFinds);

  const willFind = getByLabelText(baseElement, 'Hi', {
    // @ts-ignore
    filter: ({ props }) => props.accessibilityStates.includes('disabled'),
  });

  debug(willFind);

  // throws as expected:
  const willNotFind = getByLabelText(baseElement, 'Hi', {
    // @ts-ignore
    filter: ({ props }) => props.accessibilityStates.includes('selected'),
  });

  debug(willNotFind);
});

Problem description:

I think this is just a naming issue between filter and selector

Suggested solution:

Either update the implementation to change the named parameter to be selector or update the typings / docs to reflect that the name should be filter

Can you help us fix this issue by submitting a pull request?

Yup

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions