Comments (4)
@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:
accessibilityValue
matching relies on having exact matches, and on my machine it worked fine, as mentioned in my previous commentaccessibilityState
matching relies on some implied states, e.g. by default each view is considered to bedisabled: false
unless explicitly specified otherwise. You can read details here
from jest-native.
@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:
disabled: true
should be put insideaccessibilityState
and notaccessibilityValue
prop forView
- First two
expect
(withaccessibilityState
) are also puttingtext
intoHaveAccessibilityState
which should be put intoHaveAccessibilityView
. 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.
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.
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)
- ToBeEmpty assertion in jest-native is also used in jest-extended HOT 2
- toHaveStyle breaks if style is a nested array HOT 2
- Matcher toBeDisabled does not take into account the editable prop of TextInput HOT 3
- Missing (dist) index.js which exports all matchers for library usage HOT 4
- toBeVisible failing when used on Pressable with style function HOT 1
- Property 'toHaveTextContent' does not exist on type 'Matchers<void> & ...' (and any other matcher from library) HOT 15
- Add toBeOnTheScreen matcher to src/index exports HOT 2
- toBeOnTheScreen() not Working With React-Native HOT 5
- toBeEmptyElement isn't working as expected HOT 2
- Peer dependency error after upgrading React to 18.1.0 HOT 5
- Property 'toBeOnTheScreen' does not exist on type 'JestMatchers<ReactTestInstance>' (TS project) HOT 20
- toBeVisible ignores opacity via color property HOT 2
- Using toBeOnTheScreen() matcher requires @testing-library/react-native v10.1.0 or later to be added to your devDependencies HOT 2
- Property 'toHaveTextContent' does not exist on type 'JestMatchers<ReactTestInstance | null>'.ts(2339) HOT 2
- Cerate an eslint plugin to sudgest to use alternative jest matchers. HOT 2
- "SyntaxError: Cannot use import statement outside a module" after upgrading to react-native 0.72.4 HOT 3
- Add support for aria properties HOT 1
- refactor: migrate code to TypeScript HOT 1
- refactor: remove Ramda dependency HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jest-native.