Skip to content

Commit 676426c

Browse files
misoguyKent C. Dodds
authored and
Kent C. Dodds
committed
fix: error messages thrown by commands (#25)
* Add tests to verify error messages thrown by commands * Remove jest/valid-expect from eslintConfig Cypress uses chai for assertion causing the lint to fail * Add contributor * Update dom-testing-library to 3.12.4 * Lock cypress version to 3.1.1 * Update failing snapshot due to dom-testing-library upgrade
1 parent 16f8c65 commit 676426c

File tree

5 files changed

+54
-26
lines changed

5 files changed

+54
-26
lines changed

.all-contributorsrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@
7070
"contributions": [
7171
"code"
7272
]
73+
},
74+
{
75+
"login": "misoguy",
76+
"name": "Soo Jae Hwang",
77+
"avatar_url": "https://avatars0.githubusercontent.com/u/12230408?v=4",
78+
"profile": "https://www.ossfinder.com",
79+
"contributions": [
80+
"bug",
81+
"code",
82+
"test"
83+
]
7384
}
7485
],
7586
"repoType": "github"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
[![downloads][downloads-badge]][npmtrends]
1717
[![MIT License][license-badge]][license]
1818

19-
[![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors)
19+
[![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#contributors)
2020
[![PRs Welcome][prs-badge]][prs]
2121
[![Code of Conduct][coc-badge]][coc]
2222

@@ -100,8 +100,8 @@ Thanks goes to these people ([emoji key][emojis]):
100100

101101
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
102102
<!-- prettier-ignore -->
103-
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub><b>Kent C. Dodds</b></sub>](https://kentcdodds.com)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Code") [📖](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Tests") | [<img src="https://avatars2.githubusercontent.com/u/498274?v=4" width="100px;"/><br /><sub><b>Ivan Babak</b></sub>](https://sompylasar.github.io)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=sompylasar "Code") [🤔](#ideas-sompylasar "Ideas, Planning, & Feedback") | [<img src="https://avatars1.githubusercontent.com/u/4002543?v=4" width="100px;"/><br /><sub><b>Łukasz Gandecki</b></sub>](http://team.thebrain.pro)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=lgandecki "Code") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=lgandecki "Tests") | [<img src="https://avatars1.githubusercontent.com/u/25429764?v=4" width="100px;"/><br /><sub><b>Peter Kamps</b></sub>](https://github.com/npeterkamps)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=npeterkamps "Code") [📖](https://github.com/kentcdodds/cypress-testing-library/commits?author=npeterkamps "Documentation") [🤔](#ideas-npeterkamps "Ideas, Planning, & Feedback") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=npeterkamps "Tests") | [<img src="https://avatars3.githubusercontent.com/u/4506749?v=4" width="100px;"/><br /><sub><b>Airat Aminev</b></sub>](https://github.com/airato)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=airato "Code") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=airato "Tests") [🔧](#tool-airato "Tools") | [<img src="https://avatars0.githubusercontent.com/u/5121148?v=4" width="100px;"/><br /><sub><b>Adrian Smijulj</b></sub>](https://www.webiny.com)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=adrian1358 "Code") |
104-
| :---: | :---: | :---: | :---: | :---: | :---: |
103+
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub><b>Kent C. Dodds</b></sub>](https://kentcdodds.com)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Code") [📖](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Tests") | [<img src="https://avatars2.githubusercontent.com/u/498274?v=4" width="100px;"/><br /><sub><b>Ivan Babak</b></sub>](https://sompylasar.github.io)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=sompylasar "Code") [🤔](#ideas-sompylasar "Ideas, Planning, & Feedback") | [<img src="https://avatars1.githubusercontent.com/u/4002543?v=4" width="100px;"/><br /><sub><b>Łukasz Gandecki</b></sub>](http://team.thebrain.pro)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=lgandecki "Code") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=lgandecki "Tests") | [<img src="https://avatars1.githubusercontent.com/u/25429764?v=4" width="100px;"/><br /><sub><b>Peter Kamps</b></sub>](https://github.com/npeterkamps)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=npeterkamps "Code") [📖](https://github.com/kentcdodds/cypress-testing-library/commits?author=npeterkamps "Documentation") [🤔](#ideas-npeterkamps "Ideas, Planning, & Feedback") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=npeterkamps "Tests") | [<img src="https://avatars3.githubusercontent.com/u/4506749?v=4" width="100px;"/><br /><sub><b>Airat Aminev</b></sub>](https://github.com/airato)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=airato "Code") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=airato "Tests") [🔧](#tool-airato "Tools") | [<img src="https://avatars0.githubusercontent.com/u/5121148?v=4" width="100px;"/><br /><sub><b>Adrian Smijulj</b></sub>](https://www.webiny.com)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=adrian1358 "Code") | [<img src="https://avatars0.githubusercontent.com/u/12230408?v=4" width="100px;"/><br /><sub><b>Soo Jae Hwang</b></sub>](https://www.ossfinder.com)<br />[🐛](https://github.com/kentcdodds/cypress-testing-library/issues?q=author%3Amisoguy "Bug reports") [💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=misoguy "Code") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=misoguy "Tests") |
104+
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
105105

106106
<!-- ALL-CONTRIBUTORS-LIST:END -->
107107

cypress/integration/commands.spec.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ describe('dom-testing-library commands', () => {
33
cy.visit('/')
44
})
55
it('getByPlaceholderText', () => {
6-
cy
7-
.getByPlaceholderText('Placeholder Text')
6+
cy.getByPlaceholderText('Placeholder Text')
87
.click()
98
.type('Hello Placeholder')
109
})
@@ -14,8 +13,7 @@ describe('dom-testing-library commands', () => {
1413
})
1514

1615
it('getByLabelText', () => {
17-
cy
18-
.getByLabelText('Label For Input Labelled By Id')
16+
cy.getByLabelText('Label For Input Labelled By Id')
1917
.click()
2018
.type('Hello Input Labelled By Id')
2119
})
@@ -38,17 +36,35 @@ describe('dom-testing-library commands', () => {
3836
})
3937

4038
it('getByText within', () => {
41-
cy.get('#nested')
42-
.within(() => {
43-
cy.getByText('Button Text').click()
44-
})
39+
cy.get('#nested').within(() => {
40+
cy.getByText('Button Text').click()
41+
})
4542
})
4643

4744
it('getByText in container', () => {
48-
cy.get('#nested')
49-
.then((subject) => {
50-
cy.getByText('Button Text', { container: subject }).click()
51-
})
45+
cy.get('#nested').then(subject => {
46+
cy.getByText('Button Text', {container: subject}).click()
47+
})
48+
})
49+
50+
it('getByTestId only throws the error message', () => {
51+
const testId = 'Some random id'
52+
const errorMessage = `Unable to find an element by: [data-testid="${testId}"]`
53+
cy.on('fail', err => {
54+
expect(err.message).to.eq(errorMessage)
55+
})
56+
57+
cy.getByTestId(testId).click()
58+
})
59+
60+
it('getByText only throws the error message', () => {
61+
const text = 'Some random text'
62+
const errorMessage = `Unable to find an element with the text: ${text}. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.`
63+
cy.on('fail', err => {
64+
expect(err.message).to.eq(errorMessage)
65+
})
66+
67+
cy.getByText('Some random text').click()
5268
})
5369
})
5470

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
"author": "Kent C. Dodds <[email protected]> (http://kentcdodds.com/)",
4545
"license": "MIT",
4646
"dependencies": {
47-
"dom-testing-library": "^3.8.0"
47+
"dom-testing-library": "^3.12.4"
4848
},
4949
"devDependencies": {
50-
"cypress": "^3.0.1",
50+
"cypress": "3.1.1",
5151
"dtslint": "^0.3.0",
5252
"kcd-scripts": "^0.37.0",
5353
"npm-run-all": "^4.1.2",
@@ -62,7 +62,8 @@
6262
"extends": "./node_modules/kcd-scripts/eslint.js",
6363
"rules": {
6464
"import/prefer-default-export": "off",
65-
"import/no-unassigned-import": "off"
65+
"import/no-unassigned-import": "off",
66+
"jest/valid-expect": "off"
6667
}
6768
},
6869
"eslintIgnore": [

src/__tests__/__snapshots__/commands.js.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
exports[`exports expected commands 1`] = `
44
Array [
5-
"queryByPlaceholderText",
6-
"queryAllByPlaceholderText",
75
"getByPlaceholderText",
86
"getAllByPlaceholderText",
97
"queryByText",
@@ -22,21 +20,23 @@ Array [
2220
"queryAllBySelectText",
2321
"getBySelectText",
2422
"getAllBySelectText",
25-
"queryByTestId",
26-
"queryAllByTestId",
2723
"getByTestId",
2824
"getAllByTestId",
2925
"queryByTitle",
3026
"queryAllByTitle",
3127
"getByTitle",
3228
"getAllByTitle",
33-
"queryByValue",
34-
"queryAllByValue",
3529
"getByValue",
3630
"getAllByValue",
37-
"queryByRole",
38-
"queryAllByRole",
3931
"getAllByRole",
4032
"getByRole",
33+
"queryByPlaceholderText",
34+
"queryAllByPlaceholderText",
35+
"queryByTestId",
36+
"queryAllByTestId",
37+
"queryByValue",
38+
"queryAllByValue",
39+
"queryByRole",
40+
"queryAllByRole",
4141
]
4242
`;

0 commit comments

Comments
 (0)