-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Throw a descriptive error if the first argument supplied to a hook was not a function #6917
Throw a descriptive error if the first argument supplied to a hook was not a function #6917
Conversation
Codecov Report
@@ Coverage Diff @@
## master #6917 +/- ##
==========================================
- Coverage 66.98% 66.97% -0.01%
==========================================
Files 250 250
Lines 10365 10375 +10
Branches 4 3 -1
==========================================
+ Hits 6943 6949 +6
- Misses 3421 3425 +4
Partials 1 1
Continue to review full report at Codecov.
|
const circus = require('../index.js'); | ||
|
||
describe('hooks error throwing', () => { | ||
test.each([['beforeEach'], ['beforeAll'], ['afterEach'], ['afterAll']])( |
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.
we don't need the nested arrays, can be just test.each(['beforeEach', 'beforeAll', 'afterEach', 'afterAll'])(
expect(() => { | ||
circus[fn]('param'); | ||
}).toThrowError( | ||
`Invalid first argument, param. It must be a callback function.`, |
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.
single quotes?
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.
This is awesome, thanks!
Aww, the typing info is wrong :( (#6351) |
Thanks @SimenB 👍 |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
This PR closes #6903 By adding validation for the first argument of the following hooks:
beforeEach
beforeAll
afterEach
afterAll
If the first argument was not a function Jest will throw a descriptive error:
Additional notes
jest.each
.Test plan
Verified that passing a string as first argument will throw an error, on both jasmine and circus runners.