Feature Request: Throw error if first argument to "it" or "test" is not a string
See original GitHub issueComing from ava, you don’t need test descriptions.
The following would work.
test(() => {
jest.mock('../config', () => () => {
return { protocol: 'http', host: 'localhost', port: '9999', pathPrefix: '' }
})
const config = require('../config')()
expect(config.api.port).toBe('9999');
})
However, this doesn’t do anything in jest.
Can we throw an error if there is no function as the second argument? Or if a string is not passed into the first?
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (3 by maintainers)
Top Results From Across the Web
How to test the type of a thrown exception in Jest
From my (albeit limited) exposure to Jest, I have found that expect().toThrow() is suitable if you want to only test an error is...
Read more >try...catch - JavaScript - MDN Web Docs - Mozilla
The code in the try block is executed first, and if it throws an exception, the code in the catch block will be...
Read more >API Reference | Vitest
For example, this code asserts that an input value is not equal to 2 . If it's equal, assertion will throw an error,...
Read more >User's Manual: Functions and Variables - Apache JMeter
If an undefined function or variable is referenced, JMeter does not report/log an error ... String, TestPlanName, Return name of current test plan,...
Read more >Programming FAQ — Python 3.11.1 documentation
What is the difference between arguments and parameters? ... Why does a_tuple[i] += ['item'] raise an exception when the addition works?
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is it possible to not do this behavior, or at the very least, put the ability to toggle it off?
Maybe my use case isn’t common, but I find myself writing out a bunch of test cases first, then I begin implementing them. Getting an error thrown in that scenario clutters up the terminal with errors about “Missing second argument. It must be a callback function”.
Thanks!
Ditto what @mike-robertson said; the missing second function is (was) a deliberate feature to allow skipped tests and I use it in exactly the way that he describes, writing out test cases to be written as I think about it and filling them in later. It seems that #5558 should have checked that the first arg was a string rather than checking that two args were passed…