Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helpful test failures when incorrect require was used
When not requiring the jest specific unexpected-react, or using with the wrong renderer, fail the test with a message show how to fix it, rather than failing with "unknown assertion"
- Loading branch information
1 parent
07b8ab0
commit 417dd2b
Showing
7 changed files
with
210 additions
and
7 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
58 changes: 58 additions & 0 deletions
58
src/tests/general/incorrect-require/standard-instead-of-jest.spec.js
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,58 @@ | ||
|
||
import EmulateDom from '../../helpers/emulateDom'; | ||
|
||
import Unexpected from 'unexpected'; | ||
import UnexpectedReact from '../../../unexpected-react'; | ||
|
||
import React from 'react'; | ||
import TestUtils from 'react-addons-test-utils'; | ||
|
||
import ClickCounter from '../../components/ClickCounter'; | ||
|
||
const expect = Unexpected.clone().use(UnexpectedReact); | ||
|
||
describe('standard-instead-of-jest', function () { | ||
|
||
it('shows a helpful error message when asserting using `to match snapshot`', function () { | ||
expect(() => expect(<ClickCounter />, 'to match snapshot'), 'to throw', | ||
[ | ||
'To use the `to match snapshot` assertion with the shallow and full DOM renderers, require unexpected-react as `require(\'unexpected-react/jest\');`', | ||
'', | ||
'' | ||
].join('\n') | ||
); | ||
}); | ||
|
||
it('shows a helpful error message when asserting using `to satisfy snapshot`', function () { | ||
expect(() => expect(<ClickCounter />, 'to satisfy snapshot'), 'to throw', | ||
[ | ||
'To use the `to satisfy snapshot` assertion with the shallow and full DOM renderers, require unexpected-react as `require(\'unexpected-react/jest\');`', | ||
'', | ||
'' | ||
].join('\n') | ||
); | ||
}); | ||
|
||
it('shows a helpful error message after shallow rendering when asserting using `to match snapshot`', function () { | ||
expect(() => expect(<ClickCounter />, 'when rendered', 'to match snapshot'), 'to throw', | ||
[ | ||
'expected <ClickCounter /> when rendered', | ||
'To use the `to match snapshot` assertion with the shallow and full DOM renderers, require unexpected-react as `require(\'unexpected-react/jest\');`', | ||
'', | ||
'' | ||
].join('\n') | ||
); | ||
}); | ||
|
||
it('shows a helpful error message when asserting using `to satisfy snapshot`', function () { | ||
expect(() => expect(<ClickCounter />, 'when rendered', 'to satisfy snapshot'), 'to throw', | ||
[ | ||
'expected <ClickCounter /> when rendered', | ||
'To use the `to satisfy snapshot` assertion with the shallow and full DOM renderers, require unexpected-react as `require(\'unexpected-react/jest\');`', | ||
'', | ||
'' | ||
].join('\n') | ||
); | ||
}); | ||
|
||
}); |
40 changes: 40 additions & 0 deletions
40
src/tests/testRenderer/incorrect-require/test-renderer-instead-of-test-renderer-jest.spec.js
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,40 @@ | ||
import Unexpected from 'unexpected'; | ||
|
||
import React, { PropTypes } from 'react'; | ||
import ReactTestRenderer from 'react-test-renderer'; | ||
import UnexpectedReactTest from '../../../test-renderer'; | ||
|
||
import ClickCounter from '../../components/ClickCounter'; | ||
|
||
const expect = Unexpected.clone() | ||
.installPlugin(UnexpectedReactTest); | ||
|
||
expect.output.preferredWidth = 80; | ||
|
||
describe('test-renderer-instead-of-test-renderer-jest', function () { | ||
|
||
it('shows a helpful error message when asserting using `to match snapshot`', function () { | ||
const testRenderer = ReactTestRenderer.create(<ClickCounter />); | ||
expect(() => expect(testRenderer, 'to match snapshot'), 'to throw', | ||
'To use the `to match snapshot` assertion with the test renderer, require unexpected-react as `require(\'unexpected-react/test-renderer-jest\');`' | ||
); | ||
}); | ||
|
||
it('shows a helpful error message when asserting using `to satisfy snapshot`', function () { | ||
const testRenderer = ReactTestRenderer.create(<ClickCounter />); | ||
expect(() => expect(testRenderer, 'to satisfy snapshot'), 'to throw', | ||
'To use the `to satisfy snapshot` assertion with the test renderer, require unexpected-react as `require(\'unexpected-react/test-renderer-jest\');`' | ||
); | ||
}); | ||
|
||
it('shows a helpful error message when asserting using `to match snapshot` and the JSON output', function () { | ||
const testRenderer = ReactTestRenderer.create(<ClickCounter />); | ||
expect(() => expect(testRenderer.toJSON(), 'to match snapshot'), 'to throw', | ||
[ | ||
'To use the `to match snapshot` assertion with the test renderer, require unexpected-react as `require(\'unexpected-react/test-renderer-jest\');`', | ||
'', | ||
'Also, don\'t pass the JSON, pass the test renderer directly' | ||
].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
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 |
---|---|---|
|
@@ -52,4 +52,4 @@ module.exports = function (wallaby) { | |
}) | ||
} | ||
}; | ||
}; | ||
}; |