/
circusItTestError.test.ts
83 lines (76 loc) · 2.82 KB
/
circusItTestError.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {Global} from '@jest/types';
let circusIt: Global.It;
let circusTest: Global.It;
// using jest-jasmine2's 'it' to test jest-circus's 'it'. Had to differentiate
// the two with this alias.
const aliasCircusIt = () => {
const {it, test} = require('../');
circusIt = it;
circusTest = test;
};
aliasCircusIt();
// A few of these tests require incorrect types to throw errors and thus pass
// the test. The typechecks on jest-circus would prevent that, so
// this file has been listed in the .flowconfig ignore section.
describe('test/it error throwing', () => {
it(`it doesn't throw an error with valid arguments`, () => {
expect(() => {
circusIt('test1', () => {});
}).not.toThrowError();
});
it(`it throws error with missing callback function`, () => {
expect(() => {
// @ts-ignore: Easy, we're testing runtime errors here
circusIt('test2');
}).toThrowError(
'Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.',
);
});
it(`it throws an error when first argument isn't a string`, () => {
expect(() => {
// @ts-ignore: 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(() => {
// @ts-ignore: Easy, we're testing runtime errors here
circusIt('test4', 'test4b');
}).toThrowError(
'Invalid second argument, test4b. It must be a callback function.',
);
});
it(`test doesn't throw an error with valid arguments`, () => {
expect(() => {
circusTest('test5', () => {});
}).not.toThrowError();
});
it(`test throws error with missing callback function`, () => {
expect(() => {
// @ts-ignore: Easy, we're testing runtime errors here
circusTest('test6');
}).toThrowError(
'Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.',
);
});
it(`test throws an error when first argument isn't a string`, () => {
expect(() => {
// @ts-ignore: 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(() => {
// @ts-ignore: Easy, we're testing runtime errors here
circusTest('test8', 'test8b');
}).toThrowError(
'Invalid second argument, test8b. It must be a callback function.',
);
});
});