Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

- `[jest-resolve]` Only resolve realpath once in try-catch ([#6925](https://github.com/facebook/jest/pull/6925))
- `[expect]` Fix TypeError in `toBeInstanceOf` on `null` or `undefined` ([#6912](https://github.com/facebook/jest/pull/6912))
- `[jest-jasmine2]` Throw a descriptive error if the first argument supplied to a hook was not a function ([#6917](https://github.com/facebook/jest/pull/6917))
- `[jest-circus]` Throw a descriptive error if the first argument supplied to a hook was not a function ([#6917](https://github.com/facebook/jest/pull/6917))
- `[jest-jasmine2]` Throw a descriptive error if the first argument supplied to a hook was not a function ([#6917](https://github.com/facebook/jest/pull/6917)) and ([#6931](https://github.com/facebook/jest/pull/6931))
- `[jest-circus]` Throw a descriptive error if the first argument supplied to a hook was not a function ([#6917](https://github.com/facebook/jest/pull/6917)) and ([#6931](https://github.com/facebook/jest/pull/6931))
- `[expect]` Fix variadic custom asymmetric matchers ([#6898](https://github.com/facebook/jest/pull/6898))
- `[jest-cli]` Fix incorrect `testEnvironmentOptions` warning ([#6852](https://github.com/facebook/jest/pull/6852))
- `[jest-each]` Prevent done callback being supplied to describe ([#6843](https://github.com/facebook/jest/pull/6843))
Expand Down
10 changes: 6 additions & 4 deletions packages/jest-circus/src/__tests__/hooks_error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ describe('hooks error throwing', () => {
test.each([['beforeEach'], ['beforeAll'], ['afterEach'], ['afterAll']])(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can change this to describe.each, then have the inner for-loop be test.each

'%s throws an error when the first argument is not a function',
fn => {
expect(() => {
circus[fn]('param');
}).toThrowError(
'Invalid first argument, param. It must be a callback function.',
['String', 1, {}, Symbol('hello'), true, null, undefined].forEach(el =>
expect(() => {
circus[fn](el);
}).toThrowError(
'Invalid first argument. It must be a callback function.',
),
);
},
);
Expand Down
4 changes: 1 addition & 3 deletions packages/jest-circus/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ const _dispatchDescribe = (blockFn, blockName, mode?: BlockMode) => {

const _addHook = (fn: HookFn, hookType: HookType, hookFn, timeout: ?number) => {
if (typeof fn !== 'function') {
throw new Error(
`Invalid first argument, ${fn}. It must be a callback function.`,
);
throw new Error(`Invalid first argument. It must be a callback function.`);
}

const asyncError = new Error();
Expand Down
10 changes: 6 additions & 4 deletions packages/jest-jasmine2/src/__tests__/hooks_error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ describe('hooks error throwing', () => {
test.each([['beforeEach'], ['beforeAll'], ['afterEach'], ['afterAll']])(
'%s throws an error when the first argument is not a function',
fn => {
expect(() => {
global[fn]('param');
}).toThrowError(
'Invalid first argument, param. It must be a callback function.',
['String', 1, {}, Symbol('hello'), true, null, undefined].forEach(el =>
expect(() => {
global[fn](el);
}).toThrowError(
'Invalid first argument. It must be a callback function.',
),
);
},
);
Expand Down
24 changes: 0 additions & 24 deletions packages/jest-jasmine2/src/jasmine/Env.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,6 @@ export default function(j$) {
};

this.beforeEach = function(beforeEachFunction, timeout) {
if (typeof beforeEachFunction !== 'function') {
throw new Error(
`Invalid first argument, ${beforeEachFunction}. It must be a callback function.`,
);
}

currentDeclarationSuite.beforeEach({
fn: beforeEachFunction,
timeout() {
Expand All @@ -518,12 +512,6 @@ export default function(j$) {
};

this.beforeAll = function(beforeAllFunction, timeout) {
if (typeof beforeAllFunction !== 'function') {
throw new Error(
`Invalid first argument, ${beforeAllFunction}. It must be a callback function.`,
);
}

currentDeclarationSuite.beforeAll({
fn: beforeAllFunction,
timeout() {
Expand All @@ -533,12 +521,6 @@ export default function(j$) {
};

this.afterEach = function(afterEachFunction, timeout) {
if (typeof afterEachFunction !== 'function') {
throw new Error(
`Invalid first argument, ${afterEachFunction}. It must be a callback function.`,
);
}

currentDeclarationSuite.afterEach({
fn: afterEachFunction,
timeout() {
Expand All @@ -548,12 +530,6 @@ export default function(j$) {
};

this.afterAll = function(afterAllFunction, timeout) {
if (typeof afterAllFunction !== 'function') {
throw new Error(
`Invalid first argument, ${afterAllFunction}. It must be a callback function.`,
);
}

currentDeclarationSuite.afterAll({
fn: afterAllFunction,
timeout() {
Expand Down
20 changes: 20 additions & 0 deletions packages/jest-jasmine2/src/jasmine/jasmine_light.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,38 @@ exports.interface = function(jasmine: Jasmine, env: any) {
},

beforeEach() {
if (typeof arguments[0] !== 'function') {
throw new Error(
`Invalid first argument. It must be a callback function.`,
);
}
return env.beforeEach.apply(env, arguments);
},

afterEach() {
if (typeof arguments[0] !== 'function') {
throw new Error(
`Invalid first argument. It must be a callback function.`,
);
}
return env.afterEach.apply(env, arguments);
},

beforeAll() {
if (typeof arguments[0] !== 'function') {
throw new Error(
`Invalid first argument. It must be a callback function.`,
);
}
return env.beforeAll.apply(env, arguments);
},

afterAll() {
if (typeof arguments[0] !== 'function') {
throw new Error(
`Invalid first argument. It must be a callback function.`,
);
}
return env.afterAll.apply(env, arguments);
},

Expand Down