diff --git a/e2e/__tests__/__snapshots__/globals.test.js.snap b/e2e/__tests__/__snapshots__/globals.test.js.snap index 4e61b01522ec..c374e2667dae 100644 --- a/e2e/__tests__/__snapshots__/globals.test.js.snap +++ b/e2e/__tests__/__snapshots__/globals.test.js.snap @@ -186,3 +186,36 @@ Snapshots: 0 total Time: <> Ran all test suites." `; + +exports[`tests with no implementation 1`] = ` +"PASS __tests__/only-constructs.test.js + ✓ it + ○ skipped 2 tests + +" +`; + +exports[`tests with no implementation 2`] = ` +"Test Suites: 1 passed, 1 total +Tests: 2 skipped, 1 passed, 3 total +Snapshots: 0 total +Time: <> +Ran all test suites." +`; + +exports[`tests with no implementation with expand arg 1`] = ` +"PASS __tests__/only-constructs.test.js + ✓ it + ○ it, no implementation + ○ test, no implementation + +" +`; + +exports[`tests with no implementation with expand arg 2`] = ` +"Test Suites: 1 passed, 1 total +Tests: 2 skipped, 1 passed, 3 total +Snapshots: 0 total +Time: <> +Ran all test suites." +`; diff --git a/e2e/__tests__/globals.test.js b/e2e/__tests__/globals.test.js index af217505bd65..1ca02d31220d 100644 --- a/e2e/__tests__/globals.test.js +++ b/e2e/__tests__/globals.test.js @@ -112,7 +112,7 @@ test('only', () => { expect(summary).toMatchSnapshot(); }); -test('cannot test with no implementation', () => { +test('tests with no implementation', () => { const filename = 'only-constructs.test.js'; const content = ` it('it', () => {}); @@ -122,7 +122,7 @@ test('cannot test with no implementation', () => { writeFiles(TEST_DIR, {[filename]: content}); const {stderr, status} = runJest(DIR); - expect(status).toBe(1); + expect(status).toBe(0); const {summary} = extractSummary(stderr); expect(cleanStderr(stderr)).toMatchSnapshot(); @@ -190,7 +190,7 @@ test('only with expand arg', () => { expect(summary).toMatchSnapshot(); }); -test('cannot test with no implementation with expand arg', () => { +test('tests with no implementation with expand arg', () => { const filename = 'only-constructs.test.js'; const content = ` it('it', () => {}); @@ -200,7 +200,7 @@ test('cannot test with no implementation with expand arg', () => { writeFiles(TEST_DIR, {[filename]: content}); const {stderr, status} = runJest(DIR, ['--expand']); - expect(status).toBe(1); + expect(status).toBe(0); const {summary} = extractSummary(stderr); expect(cleanStderr(stderr)).toMatchSnapshot(); diff --git a/packages/jest-circus/src/__tests__/circus_it_test_error.test.js b/packages/jest-circus/src/__tests__/circus_it_test_error.test.js index 4fd4e2d99f27..45c920736831 100644 --- a/packages/jest-circus/src/__tests__/circus_it_test_error.test.js +++ b/packages/jest-circus/src/__tests__/circus_it_test_error.test.js @@ -33,21 +33,21 @@ describe('test/it error throwing', () => { circusIt('test1', () => {}); }).not.toThrowError(); }); - it(`it throws error with missing callback function`, () => { + it(`it doesn't throw error with missing callback function`, () => { expect(() => { - // $FlowFixMe: Easy, we're testing runitme errors here + // $FlowFixMe: Easy, we're testing runtime errors here circusIt('test2'); - }).toThrowError('Missing second argument. It must be a callback function.'); + }).not.toThrowError(); }); it(`it throws an error when first argument isn't a string`, () => { expect(() => { - // $FlowFixMe: Easy, we're testing runitme errors here + // $FlowFixMe: Easy, we're testing runtime errors here circusIt(() => {}); }).toThrowError(`Invalid first argument, () => {}. It must be a string.`); }); it('it throws an error when callback function is not a function', () => { expect(() => { - // $FlowFixMe: Easy, we're testing runitme errors here + // $FlowFixMe: Easy, we're testing runtime errors here circusIt('test4', 'test4b'); }).toThrowError( `Invalid second argument, test4b. It must be a callback function.`, @@ -58,21 +58,21 @@ describe('test/it error throwing', () => { circusTest('test5', () => {}); }).not.toThrowError(); }); - it(`test throws error with missing callback function`, () => { + it(`test doesn't throw error with missing callback function`, () => { expect(() => { - // $FlowFixMe: Easy, we're testing runitme errors here + // $FlowFixMe: Easy, we're testing runtime errors here circusTest('test6'); - }).toThrowError('Missing second argument. It must be a callback function.'); + }).not.toThrowError(); }); it(`test throws an error when first argument isn't a string`, () => { expect(() => { - // $FlowFixMe: Easy, we're testing runitme errors here + // $FlowFixMe: Easy, we're testing runtime errors here circusTest(() => {}); }).toThrowError(`Invalid first argument, () => {}. It must be a string.`); }); it('test throws an error when callback function is not a function', () => { expect(() => { - // $FlowFixMe: Easy, we're testing runitme errors here + // $FlowFixMe: Easy, we're testing runtime errors here circusTest('test8', 'test8b'); }).toThrowError( `Invalid second argument, test8b. It must be a callback function.`, diff --git a/packages/jest-circus/src/index.js b/packages/jest-circus/src/index.js index 91e315b1241d..104b3aad2639 100644 --- a/packages/jest-circus/src/index.js +++ b/packages/jest-circus/src/index.js @@ -63,10 +63,7 @@ const test = (testName: TestName, fn: TestFn, timeout?: number) => { `Invalid first argument, ${testName}. It must be a string.`, ); } - if (fn === undefined) { - throw new Error('Missing second argument. It must be a callback function.'); - } - if (typeof fn !== 'function') { + if (fn !== undefined && typeof fn !== 'function') { throw new Error( `Invalid second argument, ${fn}. It must be a callback function.`, ); diff --git a/packages/jest-jasmine2/src/__tests__/it_test_error.test.js b/packages/jest-jasmine2/src/__tests__/it_test_error.test.js index 9f1727645ffd..38b7906aea19 100644 --- a/packages/jest-jasmine2/src/__tests__/it_test_error.test.js +++ b/packages/jest-jasmine2/src/__tests__/it_test_error.test.js @@ -9,10 +9,10 @@ 'use strict'; describe('test/it error throwing', () => { - it(`it throws error with missing callback function`, () => { + it(`it doesn't throw error with missing callback function`, () => { expect(() => { it('test1'); - }).toThrowError('Missing second argument. It must be a callback function.'); + }).not.toThrowError(/argument/i); }); it(`it throws an error when first argument isn't a string`, () => { expect(() => { @@ -26,10 +26,10 @@ describe('test/it error throwing', () => { `Invalid second argument, test3b. It must be a callback function.`, ); }); - test(`test throws error with missing callback function`, () => { + test(`test doesn't throw error with missing callback function`, () => { expect(() => { test('test4'); - }).toThrowError('Missing second argument. It must be a callback function.'); + }).not.toThrowError(/argument/i); }); test(`test throws an error when first argument isn't a string`, () => { expect(() => { diff --git a/packages/jest-jasmine2/src/jasmine/Env.js b/packages/jest-jasmine2/src/jasmine/Env.js index d547c0a8f271..cddd32b63e00 100644 --- a/packages/jest-jasmine2/src/jasmine/Env.js +++ b/packages/jest-jasmine2/src/jasmine/Env.js @@ -448,12 +448,7 @@ export default function(j$) { `Invalid first argument, ${description}. It must be a string.`, ); } - if (fn === undefined) { - throw new Error( - 'Missing second argument. It must be a callback function.', - ); - } - if (typeof fn !== 'function') { + if (fn !== undefined && typeof fn !== 'function') { throw new Error( `Invalid second argument, ${fn}. It must be a callback function.`, );