Skip to content

Commit

Permalink
fix: check for second param supplied to describe block
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddie Sholl committed Jun 1, 2018
1 parent aff9681 commit fe0577e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
26 changes: 26 additions & 0 deletions e2e/__tests__/__snapshots__/globals.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,32 @@ Time: <<REPLACED>>
Ran all test suites."
`;
exports[`cannot have describe 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 | describe('describe, no implementation');
| ^
3 |
at packages/jest-jasmine2/build/jasmine/Env.js:<<LINE>>:<<COLUMN>>
at __tests__/only-constructs.test.js:<<LINE>>:<<COLUMN>>
"
`;
exports[`cannot have describe 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 1`] = `
"FAIL __tests__/only-constructs.test.js
● Test suite failed to run
Expand Down
15 changes: 15 additions & 0 deletions e2e/__tests__/globals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ test('only', () => {
expect(summary).toMatchSnapshot();
});

test('cannot have describe with no implementation', () => {
const filename = 'only-constructs.test.js';
const content = `
describe('describe, no implementation');
`;

writeFiles(TEST_DIR, {[filename]: content});
const {stderr, status} = runJest(DIR);
expect(status).toBe(1);

const {summary, rest} = extractSummary(stderr, {stripLocation: true});
expect(clean(rest)).toMatchSnapshot();
expect(clean(summary)).toMatchSnapshot();
});

test('cannot test with no implementation', () => {
const filename = 'only-constructs.test.js';
const content = `
Expand Down
14 changes: 12 additions & 2 deletions packages/jest-jasmine2/src/jasmine/Env.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,16 @@ export default function(j$) {

this.describe = function(description, specDefinitions) {
const suite = suiteFactory(description);
if (specDefinitions === undefined) {
throw new Error(
`Missing second argument supplied to 'describe'. It must be a callback function.`,
);
}
if (typeof specDefinitions !== 'function') {
throw new Error(
`Invalid second argument supplied to 'describe', ${specDefinitions}. It must be a callback function.`,
);
}
if (specDefinitions.length > 0) {
throw new Error('describe does not expect any arguments');
}
Expand Down Expand Up @@ -450,12 +460,12 @@ export default function(j$) {
}
if (fn === undefined) {
throw new Error(
'Missing second argument. It must be a callback function.',
`Missing second argument supplied to 'it'. It must be a callback function.`,
);
}
if (typeof fn !== 'function') {
throw new Error(
`Invalid second argument, ${fn}. It must be a callback function.`,
`Invalid second argument supplied to 'it', ${fn}. It must be a callback function.`,
);
}
const spec = specFactory(
Expand Down

0 comments on commit fe0577e

Please sign in to comment.