-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for react-testing-library
- Loading branch information
Raice Hannay
committed
Jul 8, 2021
1 parent
2d7279a
commit c64677e
Showing
35 changed files
with
2,447 additions
and
2,388 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
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,74 @@ | ||
Custom `react-testing-library` queries | ||
====================================== | ||
|
||
Because this functionality is missing by default and is still useful, the following custom queries | ||
are provided. | ||
|
||
## Finding by `id` | ||
- `getById` | ||
- `getAllById` | ||
- `findById` | ||
- `findAllById` | ||
- `queryById` | ||
- `queryAllById` | ||
|
||
## Finding by `className` | ||
- `getByClassName` | ||
- `getAllByClassName` | ||
- `findByClassName` | ||
- `findAllByClassName` | ||
- `queryByClassName` | ||
- `queryAllByClassName` | ||
|
||
## Finding by CSS selector | ||
- `getBySelector` | ||
- `getAllBySelector` | ||
- `findBySelector` | ||
- `findAllBySelector` | ||
- `queryBySelector` | ||
- `queryAllBySelector` | ||
|
||
|
||
## Usage | ||
### Via the return value of `.render()` | ||
The internals of all of the `Wrapper` classes integrate with the `render` function provided by | ||
`react-testing-library` to include the custom queries to be returned along with everything else that's | ||
usually returned there (such as their existing query functions). | ||
```typescript | ||
import { Wrapper } from "react-test-wrapper/react-testing-library"; | ||
|
||
const component = new Wrapper(SomeComponent); | ||
|
||
describe("when testing a scenario", () => { | ||
const { getByClassName } = component.render(); | ||
|
||
it("renders button A", () => { | ||
expect(getByClassName("SomeComponent--buttonA")).toBeDefined(); | ||
}); | ||
|
||
it("doesn't render button B", () => { | ||
expect(getByClassName("SomeComponent--buttonB")).toBeUndefined(); | ||
}); | ||
}); | ||
``` | ||
|
||
### Via the custom `screen` provided by this package | ||
If you want to use `screen`, just import the one from this package instead of their one. | ||
|
||
```typescript | ||
import { screen, Wrapper } from "react-test-wrapper/react-testing-library"; | ||
|
||
const component = new Wrapper(SomeComponent); | ||
|
||
describe("when testing a scenario", () => { | ||
component.render(); | ||
|
||
it("renders button A", () => { | ||
expect(screen.getByClassName("SomeComponent--buttonA")).toBeDefined(); | ||
}); | ||
|
||
it("doesn't render button B", () => { | ||
expect(screen.getByClassName("SomeComponent--buttonB")).toBeUndefined(); | ||
}); | ||
}); | ||
``` |
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 |
---|---|---|
@@ -1,4 +1,11 @@ | ||
import "@testing-library/react/dont-cleanup-after-each"; | ||
|
||
import { configure as configureRTL } from "@testing-library/react"; | ||
import EnzymeAdapter from "@wojtekmaj/enzyme-adapter-react-17"; | ||
import { configure } from "enzyme"; | ||
import { configure as configureEnzyme } from "enzyme"; | ||
|
||
configureEnzyme({ adapter: new EnzymeAdapter() }); | ||
|
||
configure({ adapter: new EnzymeAdapter() }); | ||
configureRTL({ | ||
testIdAttribute: "data-automationid", | ||
}); |
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 was deleted.
Oops, something went wrong.
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
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
src/WrapperWithIntl.test.tsx → src/enzyme/WrapperWithIntl.test.tsx
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
File renamed without changes.
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
File renamed without changes.
Oops, something went wrong.