-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First class support for test id's #286
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
documentation/assertions/DOMElement/queried-for-test-id.md
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,78 @@ | ||
Queries the subject element for the first descendant element with the given `data-test-id` | ||
attribute and forwards it to another assertion. | ||
|
||
If the data-test-id is not found it fails. | ||
|
||
```js | ||
var element = createElement(` | ||
<section> | ||
<h1>Numbers</h1> | ||
<hr> | ||
<ol data-test-id="numbers"> | ||
<li >One</li> | ||
<li>Two</li> | ||
<li>Three</li> | ||
</ol> | ||
</section> | ||
`); | ||
|
||
expect(element, 'queried for test id', 'numbers', 'to satisfy', { | ||
children: expect.it('to have length', 3) | ||
}); | ||
``` | ||
|
||
If no matching element can be found you get the following error: | ||
|
||
```js | ||
expect(element, 'queried for test id', 'emojies', 'to satisfy', { | ||
children: expect.it('to have length', 666) | ||
}); | ||
``` | ||
|
||
```output | ||
expected | ||
<section> | ||
<h1>Numbers</h1> | ||
<hr> | ||
<ol data-test-id="numbers"> | ||
<li>...</li> | ||
<li>...</li> | ||
<li>...</li> | ||
</ol> | ||
</section> | ||
queried for test id 'emojies' to satisfy { children: expect.it('to have length', 666) } | ||
expected DOMElement queried for first [data-test-id="emojies"] | ||
The selector [data-test-id="emojies"] yielded no results | ||
``` | ||
|
||
In case the next assertion fails you will get an error looking like this: | ||
|
||
```js | ||
expect( | ||
element, | ||
'queried for test id', | ||
'numbers', | ||
'to have no children' | ||
); | ||
``` | ||
|
||
```output | ||
expected | ||
<section> | ||
<h1>Numbers</h1> | ||
<hr> | ||
<ol data-test-id="numbers"> | ||
<li>...</li> | ||
<li>...</li> | ||
<li>...</li> | ||
</ol> | ||
</section> | ||
queried for test id 'numbers' to have no children | ||
expected | ||
<ol data-test-id="numbers"> | ||
<li>One</li> | ||
<li>Two</li> | ||
<li>Three</li> | ||
</ol> | ||
to have no children | ||
``` |
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,75 @@ | ||
Assert that an element contains a descendant element with element with the given `data-test-id` | ||
attribute. | ||
|
||
```js | ||
var element = createElement(` | ||
<section> | ||
<h1>Numbers</h1> | ||
<hr> | ||
<ol data-test-id="numbers"> | ||
<li>One</li> | ||
<li>Two</li> | ||
<li>Three</li> | ||
</ol> | ||
</section> | ||
`); | ||
|
||
expect(element, 'to contain test id', 'numbers'); | ||
``` | ||
|
||
You get the following error when it fails: | ||
|
||
```js | ||
expect(element, 'to contain test id', 'emojies'); | ||
``` | ||
|
||
```output | ||
expected | ||
<section> | ||
<h1>Numbers</h1> | ||
<hr> | ||
<ol data-test-id="numbers"> | ||
<li>...</li> | ||
<li>...</li> | ||
<li>...</li> | ||
</ol> | ||
</section> | ||
to contain test id 'emojies' | ||
expected DOMElement to contain elements matching '[data-test-id="emojies"]' | ||
``` | ||
|
||
Using the `not` flag, you can assert that the test id shouldn't be found on any | ||
descendant elements: | ||
|
||
```js | ||
expect(element, 'not to contain test id', 'emojies'); | ||
``` | ||
|
||
You get the following error when it fails: | ||
|
||
```js | ||
expect(element, 'not to contain test id', 'numbers'); | ||
``` | ||
|
||
```output | ||
expected | ||
<section> | ||
<h1>Numbers</h1> | ||
<hr> | ||
<ol data-test-id="numbers"> | ||
<li>...</li> | ||
<li>...</li> | ||
<li>...</li> | ||
</ol> | ||
</section> | ||
not to contain test id 'numbers' | ||
expected DOMElement not to contain elements matching '[data-test-id="numbers"]' | ||
|
||
NodeList[ | ||
<ol data-test-id="numbers"> | ||
<li>...</li> | ||
<li>...</li> | ||
<li>...</li> | ||
</ol> // should be removed | ||
] | ||
``` |
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,47 @@ | ||
Assert that an element have the given `data-test-id` attribute. | ||
|
||
```js | ||
var element = createElement(` | ||
<button data-test-id="publish" class="primary" disabled> | ||
Publish | ||
</button> | ||
`); | ||
|
||
expect(element, 'to have test id', 'publish'); | ||
``` | ||
|
||
In case of a failing expectation you get the following output: | ||
|
||
```js | ||
expect(element, 'to have test id', 'approve'); | ||
``` | ||
|
||
```output | ||
expected | ||
<button data-test-id="publish" class="primary" disabled> | ||
Publish | ||
</button> | ||
to have test id 'approve' | ||
expected DOMElement to match '[data-test-id="approve"]' | ||
``` | ||
|
||
You can also assert that an element does not have a test id: | ||
|
||
```js | ||
expect(element, 'not to have test id', 'approve'); | ||
``` | ||
|
||
In case of a failing expectation you get the following output: | ||
|
||
```js | ||
expect(element, 'not to have test id', 'publish'); | ||
``` | ||
|
||
```output | ||
expected | ||
<button data-test-id="publish" class="primary" disabled> | ||
Publish | ||
</button> | ||
not to have test id 'publish' | ||
expected DOMElement not to match '[data-test-id="publish"]' | ||
``` |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this to avoid dotting out? Is it something we want in some of the other assertions as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I have experience cases where we dot out stuff that contains conflicts. We should go through all of the assertions and make sure that we don't remove useful information, but that is a separate task: #287