Skip to content

Commit

Permalink
Complain if expect is passed multiple arguments (#4237)
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavnikolaj authored and cpojer committed Aug 10, 2017
1 parent e16ce6b commit 8a0bdd2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/jest-matchers/src/__tests__/matchers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
const {stringify} = require('jest-matcher-utils');
const jestExpect = require('../');

it('should throw if passed two arguments', () => {
expect(() => jestExpect('foo', 'bar')).toThrow(
new Error('Expect takes at most one argument.'),
);
});

describe('.rejects', () => {
it('should reject', async () => {
await jestExpect(Promise.reject(4)).rejects.toBe(4);
Expand Down
6 changes: 5 additions & 1 deletion packages/jest-matchers/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ const isPromise = obj => {
);
};

const expect = (actual: any): ExpectationObject => {
const expect = (actual: any, ...rest): ExpectationObject => {
if (rest.length !== 0) {
throw new Error('Expect takes at most one argument.');
}

const allMatchers = getMatchers();
const expectation = {
not: {},
Expand Down

0 comments on commit 8a0bdd2

Please sign in to comment.