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

Re-allowed single string arguments for pending tests #6602

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Features

- `[jest-jasmine2]` Updated error throwing with `it`/ `test` to re-allow the valid single string argument for pending tests.
- `[jest-circus]` Updated error throwing with `it`/ `test` to re-allow the valid single string argument for pending tests
- `[jest-haste-map]` Add `computeDependencies` flag to avoid opening files if not needed ([#6667](https://github.com/facebook/jest/pull/6667))
- `[jest-runtime]` Support `require.resolve.paths` ([#6471](https://github.com/facebook/jest/pull/6471))
- `[jest-runtime]` Support `paths` option for `require.resolve` ([#6471](https://github.com/facebook/jest/pull/6471))
Expand Down
87 changes: 33 additions & 54 deletions e2e/__tests__/__snapshots__/globals.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,6 @@ Time: <<REPLACED>>
Ran all test suites."
`;

exports[`cannot test with no implementation 1`] = `
"FAIL __tests__/only-constructs.test.js
● Test suite failed to run

Missing second argument. It must be a callback function.

1 |
2 | it('it', () => {});
> 3 | it('it, no implementation');
| ^
4 | test('test, no implementation');
5 |

at __tests__/only-constructs.test.js:3:5

"
`;

exports[`cannot test with no implementation 2`] = `
"Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites.
"
`;

exports[`cannot test with no implementation with expand arg 1`] = `
"FAIL __tests__/only-constructs.test.js
● Test suite failed to run

Missing second argument. It must be a callback function.

1 |
2 | it('it', () => {});
> 3 | it('it, no implementation');
| ^
4 | test('test, no implementation');
5 |

at __tests__/only-constructs.test.js:3:5

"
`;

exports[`cannot test with no implementation with expand arg 2`] = `
"Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites.
"
`;

exports[`function as descriptor 1`] = `
"PASS __tests__/function-as-descriptor.test.js
Foo
Expand Down Expand Up @@ -186,3 +132,36 @@ Snapshots: 0 total
Time: <<REPLACED>>
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: <<REPLACED>>
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: <<REPLACED>>
Ran all test suites."
`;
8 changes: 4 additions & 4 deletions e2e/__tests__/globals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {});
Expand All @@ -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();
Expand Down Expand Up @@ -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', () => {});
Expand All @@ -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();
Expand Down
20 changes: 10 additions & 10 deletions packages/jest-circus/src/__tests__/circus_it_test_error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
Expand All @@ -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.`,
Expand Down
6 changes: 2 additions & 4 deletions packages/jest-circus/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
);
Expand All @@ -80,6 +77,7 @@ const test = (testName: TestName, fn: TestFn, timeout?: number) => {
return dispatch({
asyncError,
fn,
mode: fn ? undefined : 'skip',
name: 'add_test',
testName,
timeout,
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-jasmine2/src/__tests__/it_test_error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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(() => {
Expand Down
7 changes: 1 addition & 6 deletions packages/jest-jasmine2/src/jasmine/Env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
);
Expand Down