support .withArgs() on expect(fn)
See original GitHub issueexpect.js has a feature to pass arguments to a function using the following syntax
expect(fn).withArgs(some, args).to.throw();
Right now I’m having to write the following
expect(() => fn(some, args)).to.throw();
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:14 (11 by maintainers)
Top Results From Across the Web
Can I mock functions with specific arguments using Jest?
I found this library that a colleague of mine wrote recently: jest-when import { when } from 'jest-when'; const fn = jest.fn(); when(fn)....
Read more >Mock Functions - Jest
Mock functions allow you to test the links between code by erasing the actual implementation of a function, capturing calls to the function ......
Read more >Stubs - Sinon.JS
Test stubs are functions (spies) with pre-programmed behavior. They support the full test spy API in addition to methods which can be used...
Read more >Jest assert over single or specific argument/parameters with ...
You can use expect.anything() to ignore certain parameters that a mock Jest function is called with, see the following:.
Read more >jest-when - npm
const fn = jest.fn() // 1) Start with any normal jest mock function when(fn) ... spyOn functions with when(); Supports function matchers ...
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
Would probably fit more with the rest of the code. Having
args
as the assertion actually makes for some interesting developments:It becomes challenging though - because we can’t assert on the error that is being thrown in a sensible way:
Whereas if the args was in the chain, then we can:
@blockloop IMO that is not a viable solution because it adds another property to the
Object.prototype
. I think that havingshould
is already enough. If we did that it would be like a new Assertion interface.