-
-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename toHaveBeenCalledOnceWith to toHaveBeenCalledExactlyOnceWith (c…
- Loading branch information
1 parent
18680e8
commit 2adf683
Showing
7 changed files
with
40 additions
and
40 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
20 changes: 10 additions & 10 deletions
20
...s__/toHaveBeenCalledOnceWith.test.js.snap → ...aveBeenCalledExactlyOnceWith.test.js.snap
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 |
---|---|---|
@@ -1,34 +1,34 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`.not.toHaveBeenCalledOnceWith fails if mock was invoked exactly once with the expected value 1`] = ` | ||
"<dim>expect(</intensity><red>received</color><dim>).not.toHaveBeenCalledOnceWith()</intensity> | ||
exports[`.not.toHaveBeenCalledExactlyOnceWith fails if mock was invoked exactly once with the expected value 1`] = ` | ||
"<dim>expect(</intensity><red>received</color><dim>).not.toHaveBeenCalledExactlyOnceWith()</intensity> | ||
Expected mock to be invoked some number of times other than once or once with arguments other than <green>["hello"]</color>, but was invoked <red>1</color> times with <red>"hello"</color>" | ||
`; | ||
|
||
exports[`.toHaveBeenCalledOnceWith fails if mock was invoked more than once, indicating how many times it was invoked 1`] = ` | ||
"<dim>expect(</intensity><red>received</color><dim>).toHaveBeenCalledOnceWith(</intensity><green>expected</color><dim>)</intensity> | ||
exports[`.toHaveBeenCalledExactlyOnceWith fails if mock was invoked more than once, indicating how many times it was invoked 1`] = ` | ||
"<dim>expect(</intensity><red>received</color><dim>).toHaveBeenCalledExactlyOnceWith(</intensity><green>expected</color><dim>)</intensity> | ||
Expected mock function to have been called exactly once, but it was called <red>17</color> times" | ||
`; | ||
|
||
exports[`.toHaveBeenCalledOnceWith fails if mock was never invoked indicating that it was invoked 0 times 1`] = ` | ||
"<dim>expect(</intensity><red>received</color><dim>).toHaveBeenCalledOnceWith(</intensity><green>expected</color><dim>)</intensity> | ||
exports[`.toHaveBeenCalledExactlyOnceWith fails if mock was never invoked indicating that it was invoked 0 times 1`] = ` | ||
"<dim>expect(</intensity><red>received</color><dim>).toHaveBeenCalledExactlyOnceWith(</intensity><green>expected</color><dim>)</intensity> | ||
Expected mock function to have been called exactly once, but it was called <red>0</color> times" | ||
`; | ||
|
||
exports[`.toHaveBeenCalledOnceWith fails when given value is not a jest spy or mock 1`] = ` | ||
"<dim>expect(</intensity><red>received</color><dim>).toHaveBeenCalledOnceWith()</intensity> | ||
exports[`.toHaveBeenCalledExactlyOnceWith fails when given value is not a jest spy or mock 1`] = ` | ||
"<dim>expect(</intensity><red>received</color><dim>).toHaveBeenCalledExactlyOnceWith()</intensity> | ||
Matcher error: <red>"received"</color> must be a mock or spy function | ||
Received has type: function | ||
Received has value: <red>[Function mock1]</color>" | ||
`; | ||
|
||
exports[`.toHaveBeenCalledOnceWith fails when given value is not the expected one 1`] = ` | ||
"<dim>expect(</intensity><red>received</color><dim>).toHaveBeenCalledOnceWith(</intensity><green>expected</color><dim>)</intensity> | ||
exports[`.toHaveBeenCalledExactlyOnceWith fails when given value is not the expected one 1`] = ` | ||
"<dim>expect(</intensity><red>received</color><dim>).toHaveBeenCalledExactlyOnceWith(</intensity><green>expected</color><dim>)</intensity> | ||
Expected mock function to have been called exactly once with <green>["hello"]</color>, but it was called with <red>"not hello"</color>" | ||
`; |
32 changes: 16 additions & 16 deletions
32
...matchers/toHaveBeenCalledOnceWith.test.js → ...s/toHaveBeenCalledExactlyOnceWith.test.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 |
---|---|---|
@@ -1,82 +1,82 @@ | ||
import * as matcher from 'src/matchers/toHaveBeenCalledOnceWith'; | ||
import * as matcher from 'src/matchers/toHaveBeenCalledExactlyOnceWith'; | ||
|
||
expect.extend(matcher); | ||
|
||
describe('.toHaveBeenCalledOnceWith', () => { | ||
describe('.toHaveBeenCalledExactlyOnceWith', () => { | ||
let mock; | ||
beforeEach(() => { | ||
mock = jest.fn(); | ||
}); | ||
|
||
test('passes if mock was invoked exactly once with the expected value', () => { | ||
mock('hello'); | ||
expect(mock).toHaveBeenCalledOnceWith('hello'); | ||
expect(mock).toHaveBeenCalledExactlyOnceWith('hello'); | ||
}); | ||
|
||
test('passes if mock was invoked exactly once with the expected values in an array', () => { | ||
mock(['hello', 'there']); | ||
expect(mock).toHaveBeenCalledOnceWith(['hello', 'there']); | ||
expect(mock).toHaveBeenCalledExactlyOnceWith(['hello', 'there']); | ||
}); | ||
|
||
test('passes if mock was invoked exactly once with the expected values', () => { | ||
mock('hello', 'there'); | ||
expect(mock).toHaveBeenCalledOnceWith('hello', 'there'); | ||
expect(mock).toHaveBeenCalledExactlyOnceWith('hello', 'there'); | ||
}); | ||
|
||
test('fails if mock was never invoked indicating that it was invoked 0 times', () => { | ||
expect(() => expect(mock).toHaveBeenCalledOnceWith('hello')).toThrowErrorMatchingSnapshot(); | ||
expect(() => expect(mock).toHaveBeenCalledExactlyOnceWith('hello')).toThrowErrorMatchingSnapshot(); | ||
}); | ||
|
||
test('fails if mock was invoked more than once, indicating how many times it was invoked', () => { | ||
// Invoke mock 17 times | ||
new Array(17).fill(mock).forEach(e => e(Math.random())); | ||
expect(() => expect(mock).toHaveBeenCalledOnceWith('hello')).toThrowErrorMatchingSnapshot(); | ||
expect(() => expect(mock).toHaveBeenCalledExactlyOnceWith('hello')).toThrowErrorMatchingSnapshot(); | ||
}); | ||
|
||
test('fails when given value is not a jest spy or mock', () => { | ||
const mock1 = () => {}; | ||
expect(() => expect(mock1).toHaveBeenCalledOnceWith('hello')).toThrowErrorMatchingSnapshot(); | ||
expect(() => expect(mock1).toHaveBeenCalledExactlyOnceWith('hello')).toThrowErrorMatchingSnapshot(); | ||
}); | ||
|
||
test('fails when given value is not the expected one', () => { | ||
mock('not hello'); | ||
expect(() => expect(mock).toHaveBeenCalledOnceWith('hello')).toThrowErrorMatchingSnapshot(); | ||
expect(() => expect(mock).toHaveBeenCalledExactlyOnceWith('hello')).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('.not.toHaveBeenCalledOnceWith', () => { | ||
describe('.not.toHaveBeenCalledExactlyOnceWith', () => { | ||
let mock; | ||
beforeEach(() => { | ||
mock = jest.fn(); | ||
}); | ||
|
||
test('passes if mock was never invoked', () => { | ||
expect(mock).not.toHaveBeenCalledOnceWith('hello'); | ||
expect(mock).not.toHaveBeenCalledExactlyOnceWith('hello'); | ||
}); | ||
|
||
test('passes if mock was invoked more than once', () => { | ||
mock('hello'); | ||
mock('hello'); | ||
expect(mock).not.toHaveBeenCalledOnceWith('hello'); | ||
expect(mock).not.toHaveBeenCalledExactlyOnceWith('hello'); | ||
}); | ||
|
||
test('fails if mock was invoked exactly once with the expected value', () => { | ||
mock('hello'); | ||
expect(() => expect(mock).not.toHaveBeenCalledOnceWith('hello')).toThrowErrorMatchingSnapshot(); | ||
expect(() => expect(mock).not.toHaveBeenCalledExactlyOnceWith('hello')).toThrowErrorMatchingSnapshot(); | ||
}); | ||
|
||
test('passes if mock was invoked exactly once without the expected value', () => { | ||
mock('not hello'); | ||
expect(mock).not.toHaveBeenCalledOnceWith('hello'); | ||
expect(mock).not.toHaveBeenCalledExactlyOnceWith('hello'); | ||
}); | ||
|
||
test('passes if mock was invoked exactly once without both expected values in an array', () => { | ||
mock(['hello', 'there']); | ||
expect(mock).not.toHaveBeenCalledOnceWith(['hello', 'not there']); | ||
expect(mock).not.toHaveBeenCalledExactlyOnceWith(['hello', 'not there']); | ||
}); | ||
|
||
test('passes if mock was invoked exactly once without both expected values', () => { | ||
mock('hello', 'there'); | ||
expect(mock).not.toHaveBeenCalledOnceWith('hello', 'not there'); | ||
expect(mock).not.toHaveBeenCalledExactlyOnceWith('hello', 'not there'); | ||
}); | ||
}); |
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