Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Add getByTestId utility * Updates to getByTestId documentation * minor tweaks
- Loading branch information
Showing
14 changed files
with
143 additions
and
51 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
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,15 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`getByTestId finds matching element 1`] = ` | ||
<span | ||
data-testid="test-component" | ||
/> | ||
`; | ||
|
||
exports[`getByTestId throws error when no matching element exists 1`] = `"Unable to find element by [data-testid=\\"unknown-data-testid\\"]"`; | ||
|
||
exports[`queryByTestId finds matching element 1`] = ` | ||
<span | ||
data-testid="test-component" | ||
/> | ||
`; |
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,26 @@ | ||
import React from 'react' | ||
import {render} from '../' | ||
|
||
const TestComponent = () => <span data-testid="test-component" /> | ||
|
||
test('queryByTestId finds matching element', () => { | ||
const {queryByTestId} = render(<TestComponent />) | ||
expect(queryByTestId('test-component')).toMatchSnapshot() | ||
}) | ||
|
||
test('queryByTestId returns null when no matching element exists', () => { | ||
const {queryByTestId} = render(<TestComponent />) | ||
expect(queryByTestId('unknown-data-testid')).toBeNull() | ||
}) | ||
|
||
test('getByTestId finds matching element', () => { | ||
const {getByTestId} = render(<TestComponent />) | ||
expect(getByTestId('test-component')).toMatchSnapshot() | ||
}) | ||
|
||
test('getByTestId throws error when no matching element exists', () => { | ||
const {getByTestId} = render(<TestComponent />) | ||
expect(() => | ||
getByTestId('unknown-data-testid'), | ||
).toThrowErrorMatchingSnapshot() | ||
}) |
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
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
Oops, something went wrong.