diff --git a/packages/jest-matchers/src/__tests__/matchers.test.js b/packages/jest-matchers/src/__tests__/matchers.test.js index a800689c6768..572f1a2f27c2 100644 --- a/packages/jest-matchers/src/__tests__/matchers.test.js +++ b/packages/jest-matchers/src/__tests__/matchers.test.js @@ -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); diff --git a/packages/jest-matchers/src/index.js b/packages/jest-matchers/src/index.js index bc1397202542..9e94a316f47a 100644 --- a/packages/jest-matchers/src/index.js +++ b/packages/jest-matchers/src/index.js @@ -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: {},