Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Regression: Allow toHaveBeenCalledWith and related functions to test calls with no arguments #1951

Merged
merged 3 commits into from
Oct 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ But it was last called with:
and two more calls."
`;

exports[`test lastCalledWith works with jest.fn and no arguments 1`] = `
exports[`test lastCalledWith works with jest.fn when not called 1`] = `
"expect(jest.fn()).lastCalledWith(expected)

Expected mock function to have been last called with:
Expand Down Expand Up @@ -137,7 +137,7 @@ But it was called with:
[\"foo\", \"bar3\"], [\"foo\", \"bar2\"], [\"foo\", \"bar1\"]"
`;

exports[`test toBeCalledWith works with jest.fn and no arguments 1`] = `
exports[`test toBeCalledWith works with jest.fn when not called 1`] = `
"expect(jest.fn()).toBeCalledWith(expected)

Expected mock function to have been called with:
Expand Down Expand Up @@ -235,7 +235,7 @@ But it was called with:
[\"foo\", \"bar3\"], [\"foo\", \"bar2\"], [\"foo\", \"bar1\"]"
`;

exports[`test toHaveBeenCalledWith works with jasmine.createSpy and no arguments 1`] = `
exports[`test toHaveBeenCalledWith works with jasmine.createSpy when not called 1`] = `
"expect(spy).toHaveBeenCalledWith(expected)

Expected spy to have been called with:
Expand Down Expand Up @@ -275,7 +275,7 @@ But it was called with:
[\"foo\", \"bar3\"], [\"foo\", \"bar2\"], [\"foo\", \"bar1\"]"
`;

exports[`test toHaveBeenCalledWith works with jest.fn and no arguments 1`] = `
exports[`test toHaveBeenCalledWith works with jest.fn when not called 1`] = `
"expect(jest.fn()).toHaveBeenCalledWith(expected)

Expected mock function to have been called with:
Expand Down Expand Up @@ -324,7 +324,7 @@ But it was last called with:
and two more calls."
`;

exports[`test toHaveBeenLastCalledWith works with jasmine.createSpy and no arguments 1`] = `
exports[`test toHaveBeenLastCalledWith works with jasmine.createSpy when not called 1`] = `
"expect(spy).toHaveBeenLastCalledWith(expected)

Expected spy to have been last called with:
Expand Down Expand Up @@ -365,7 +365,7 @@ But it was last called with:
and two more calls."
`;

exports[`test toHaveBeenLastCalledWith works with jest.fn and no arguments 1`] = `
exports[`test toHaveBeenLastCalledWith works with jest.fn when not called 1`] = `
"expect(jest.fn()).toHaveBeenLastCalledWith(expected)

Expected mock function to have been last called with:
Expand Down
9 changes: 8 additions & 1 deletion packages/jest-matchers/src/__tests__/spyMatchers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,21 @@ describe('toHaveBeenCalledTimes', () => {
const getFunction = () => {
return mockName === 'jest.fn' ? jest.fn() : jasmine.createSpy('fn');
};
test(`${calledWith} works with ${mockName} and no arguments`, () => {

test(`${calledWith} works with ${mockName} when not called`, () => {
const fn = getFunction();
jestExpect(fn).not[calledWith]('foo', 'bar');

expect(() => jestExpect(fn)[calledWith]('foo', 'bar'))
.toThrowErrorMatchingSnapshot();
});

test(`${calledWith} works with ${mockName} and no arguments`, () => {
const fn = getFunction();
fn();
jestExpect(fn)[calledWith]();
});

test(`${calledWith} works with ${mockName} and arguments that don't match`, () => {
const fn = getFunction();
fn('foo', 'bar1');
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-matchers/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const makeThrowingMatcher = (
isNot: boolean,
actual: any,
): ThrowingMatcherFn => {
return function throwingMatcher(expected, ...rest) {
return function throwingMatcher(...args) {
let throws = true;
const matcherContext: MatcherContext = Object.assign(
// When throws is disabled, the matcher will not throw errors during test
Expand All @@ -74,7 +74,7 @@ const makeThrowingMatcher = (
try {
result = matcher.apply(
matcherContext,
[actual, expected].concat(rest),
[actual].concat(args),
);
} catch (error) {
// Remove this and deeper functions from the stack trace frame.
Expand Down