-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: create always passing toBeBusy() matcher * test: prepare toBeBusy() tests * feat: implement toBeBusy() passing condition * feat: implement error message * test: update error message snapshots to correct format * refactor: use screen variable * refactor: tweaks * refactor: cleanup * refactor: clean up * refactor: finishing touches --------- Co-authored-by: Maciej Jastrzębski <mdjastrzebski@gmail.com>
- Loading branch information
1 parent
1592d35
commit 701433c
Showing
8 changed files
with
146 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import * as React from 'react'; | ||
import { View } from 'react-native'; | ||
import { render, screen } from '../..'; | ||
import '../extend-expect'; | ||
|
||
test('toBeBusy() basic case', () => { | ||
render( | ||
<> | ||
<View testID="busy" accessibilityState={{ busy: true }} /> | ||
<View testID="busy-aria" aria-busy /> | ||
<View testID="not-busy" accessibilityState={{ busy: false }} /> | ||
<View testID="not-busy-aria" aria-busy={false} /> | ||
<View testID="default" /> | ||
</> | ||
); | ||
|
||
expect(screen.getByTestId('busy')).toBeBusy(); | ||
expect(screen.getByTestId('busy-aria')).toBeBusy(); | ||
expect(screen.getByTestId('not-busy')).not.toBeBusy(); | ||
expect(screen.getByTestId('not-busy-aria')).not.toBeBusy(); | ||
expect(screen.getByTestId('default')).not.toBeBusy(); | ||
}); | ||
|
||
test('toBeBusy() error messages', () => { | ||
render( | ||
<> | ||
<View testID="busy" accessibilityState={{ busy: true }} /> | ||
<View testID="busy-aria" aria-busy /> | ||
<View testID="not-busy" accessibilityState={{ busy: false }} /> | ||
<View testID="not-busy-aria" aria-busy={false} /> | ||
<View testID="default" /> | ||
</> | ||
); | ||
|
||
expect(() => expect(screen.getByTestId('busy')).not.toBeBusy()) | ||
.toThrowErrorMatchingInlineSnapshot(` | ||
"expect(element).not.toBeBusy() | ||
Received element is busy: | ||
<View | ||
accessibilityState={ | ||
{ | ||
"busy": true, | ||
} | ||
} | ||
testID="busy" | ||
/>" | ||
`); | ||
|
||
expect(() => expect(screen.getByTestId('busy-aria')).not.toBeBusy()) | ||
.toThrowErrorMatchingInlineSnapshot(` | ||
"expect(element).not.toBeBusy() | ||
Received element is busy: | ||
<View | ||
aria-busy={true} | ||
testID="busy-aria" | ||
/>" | ||
`); | ||
|
||
expect(() => expect(screen.getByTestId('not-busy')).toBeBusy()) | ||
.toThrowErrorMatchingInlineSnapshot(` | ||
"expect(element).toBeBusy() | ||
Received element is not busy: | ||
<View | ||
accessibilityState={ | ||
{ | ||
"busy": false, | ||
} | ||
} | ||
testID="not-busy" | ||
/>" | ||
`); | ||
|
||
expect(() => expect(screen.getByTestId('not-busy-aria')).toBeBusy()) | ||
.toThrowErrorMatchingInlineSnapshot(` | ||
"expect(element).toBeBusy() | ||
Received element is not busy: | ||
<View | ||
aria-busy={false} | ||
testID="not-busy-aria" | ||
/>" | ||
`); | ||
|
||
expect(() => expect(screen.getByTestId('default')).toBeBusy()) | ||
.toThrowErrorMatchingInlineSnapshot(` | ||
"expect(element).toBeBusy() | ||
Received element is not busy: | ||
<View | ||
testID="default" | ||
/>" | ||
`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ReactTestInstance } from 'react-test-renderer'; | ||
import { matcherHint } from 'jest-matcher-utils'; | ||
import { isElementBusy } from '../helpers/accessiblity'; | ||
import { checkHostElement, formatElement } from './utils'; | ||
|
||
export function toBeBusy( | ||
this: jest.MatcherContext, | ||
element: ReactTestInstance | ||
) { | ||
checkHostElement(element, toBeBusy, this); | ||
|
||
return { | ||
pass: isElementBusy(element), | ||
message: () => { | ||
const matcher = matcherHint( | ||
`${this.isNot ? '.not' : ''}.toBeBusy`, | ||
'element', | ||
'' | ||
); | ||
return [ | ||
matcher, | ||
'', | ||
`Received element is ${this.isNot ? '' : 'not '}busy:`, | ||
formatElement(element), | ||
].join('\n'); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters