Giter Club home page Giter Club logo

Comments (4)

mdjastrzebski avatar mdjastrzebski commented on June 15, 2024 1

@gkartalis in your example the View had accessibilityValue prop, but it did not have accessibilityState.
Matching of these two props has differences derived from React Native + iOS/Android accessibility behavior:

  1. accessibilityValue matching relies on having exact matches, and on my machine it worked fine, as mentioned in my previous comment
  2. accessibilityState matching relies on some implied states, e.g. by default each view is considered to be disabled: false unless explicitly specified otherwise. You can read details here

from jest-native.

mdjastrzebski avatar mdjastrzebski commented on June 15, 2024

@gkartalis not sure what exactly is happening at your side, so I'll do my best to address your issue.

I've spotted few errors in your test code:

  1. disabled: true should be put inside accessibilityState and not accessibilityValue prop for View
  2. First two expect (with accessibilityState) are also putting text in toHaveAccessibilityState which should be put in toHaveAccessibilityView. They are also the same, despite comments about one failing and other not.

The following test passes correctly on my side:

test('issue', () => {
  render(
    <View
      testID="view"
      accessibilityValue={{ text: 'Almost full' }}
      accessibilityState={{ disabled: true }}
    />
  );

  const view = screen.getByTestId('view');

  expect(view).toHaveAccessibilityState({ disabled: true });
  expect(view).not.toHaveAccessibilityState({ disabled: false });

  expect(view).toHaveAccessibilityValue({ text: 'Almost full' });
  expect(view).not.toHaveAccessibilityValue({ text: 'Whatever this is wrong' });
});

Let me know if correcting the spotted issues resolves the error for you. If not then pls prepare a minimal repro repository based on RNTL basic example, so that I can reproduce the issue locally.

from jest-native.

gkartalis avatar gkartalis commented on June 15, 2024

Gotcha, honestly I went ahead and thought thattoHaveAccessibilityValue is the same as toHaveAccessibilityState but partial for a single state value. That was also the reason that my example was like that.

I can now close the issue then, but the thing is that toHaveAccessibilityValue was not failing even though I didn't have any accessibilityValue prop included 🤔, any way closing the issue.

Thanks for the response!

from jest-native.

gkartalis avatar gkartalis commented on June 15, 2024

Good point good point it was an unfortunate typo :D . But thanks for the links (I will also edit the initial post to reflect that)

from jest-native.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.