https://github.com/hugodf/jest-specific-argument-assert
Jest assert over single or specific argument/parameters with .toHaveBeenCalledWith and expect.anything()
https://github.com/hugodf/jest-specific-argument-assert
Last synced: 24 days ago
JSON representation
Jest assert over single or specific argument/parameters with .toHaveBeenCalledWith and expect.anything()
- Host: GitHub
- URL: https://github.com/hugodf/jest-specific-argument-assert
- Owner: HugoDF
- License: mit
- Created: 2019-04-28T19:15:06.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T02:50:25.000Z (over 2 years ago)
- Last Synced: 2025-02-14T01:39:38.217Z (3 months ago)
- Language: JavaScript
- Homepage: https://codewithhugo.com/jest-specific-argument-parameter-assert/
- Size: 760 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jest-specific-argument-assert
> Jest assert over single or specific argument/parameters with .toHaveBeenCalledWith and expect.anything()
See it in action at https://codesandbox.io/s/github/HugoDF/jest-specific-argument-assert/tree/master/
Most of the interesting things happen in [./src/pinger.test.js](./src/pinger.test.js).
To run the tests:
- `npm install` (Node 10+, npm 6+)
- `npm test` to run tests (or `npm test -- --coverage` to run with coverage)Note the use of `expect.anyting()` to ignore certain parameters to a function that aren't asserted against for specific tests.
```js
describe('without search', () => {
test('calls getPingConfigs with right accountId, searchRegex', async () => {
await pinger(1);
expect(mockPingConfig).toHaveBeenCalledWith(
1,
expect.anything(),
expect.anything(),
new RegExp('.*')
);
});
});
describe('offset, limit', () => {
test('calls getPingConfigs with passed offset and limit', async () => {
await pinger(1, { offset: 20, limit: 100 });
expect(mockPingConfig).toHaveBeenCalledWith(
1,
20,
100,
expect.anything()
);
});
test('calls getPingConfigs with default offset and limit if undefined', async () => {
await pinger(1);
expect(mockPingConfig).toHaveBeenCalledWith(1, 0, 50, expect.anything());
});
});
describe('search', () => {
describe('single-word search', () => {
test('calls getPingConfigs with right accountId, searchRegex', async () => {
await pinger(1, {}, 'search');
expect(mockPingConfig).toHaveBeenCalledWith(
1,
expect.anything(),
expect.anything(),
new RegExp('search')
);
});
});
describe('multi-word search', () => {
test('calls getPingConfigs with right accountId, searchRegex', async () => {
await pinger(1, {}, 'multi word search');
expect(mockPingConfig).toHaveBeenCalledWith(
1,
expect.anything(),
expect.anything(),
new RegExp('multi|word|search')
);
});
});
});
```