1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.installErrorOnPrivate = installErrorOnPrivate;
|
7 |
|
8 | var _jestUtil = require('jest-util');
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | const disabledGlobals = {
|
18 | fail: 'Illegal usage of global `fail`, prefer throwing an error, or the `done.fail` callback.',
|
19 | pending: 'Illegal usage of global `pending`, prefer explicitly skipping a test using `test.skip`',
|
20 | spyOn: 'Illegal usage of global `spyOn`, prefer `jest.spyOn`.',
|
21 | spyOnProperty: 'Illegal usage of global `spyOnProperty`, prefer `jest.spyOn`.'
|
22 | };
|
23 |
|
24 | const disabledJasmineMethods = {
|
25 | addMatchers: 'Illegal usage of `jasmine.addMatchers`, prefer `expect.extends`.',
|
26 | any: 'Illegal usage of `jasmine.any`, prefer `expect.any`.',
|
27 | anything: 'Illegal usage of `jasmine.anything`, prefer `expect.anything`.',
|
28 | arrayContaining: 'Illegal usage of `jasmine.arrayContaining`, prefer `expect.arrayContaining`.',
|
29 | createSpy: 'Illegal usage of `jasmine.createSpy`, prefer `jest.fn`.',
|
30 | objectContaining: 'Illegal usage of `jasmine.objectContaining`, prefer `expect.objectContaining`.',
|
31 | stringMatching: 'Illegal usage of `jasmine.stringMatching`, prefer `expect.stringMatching`.'
|
32 | };
|
33 |
|
34 | function installErrorOnPrivate(global) {
|
35 | const jasmine = global.jasmine;
|
36 | Object.keys(disabledGlobals).forEach(functionName => {
|
37 | global[functionName] = () => {
|
38 | throwAtFunction(disabledGlobals[functionName], global[functionName]);
|
39 | };
|
40 | });
|
41 | Object.keys(disabledJasmineMethods).forEach(methodName => {
|
42 |
|
43 | jasmine[methodName] = () => {
|
44 | throwAtFunction(disabledJasmineMethods[methodName], jasmine[methodName]);
|
45 | };
|
46 | });
|
47 |
|
48 | function set() {
|
49 | throwAtFunction(
|
50 | 'Illegal usage of `jasmine.DEFAULT_TIMEOUT_INTERVAL`, prefer `jest.setTimeout`.',
|
51 | set
|
52 | );
|
53 | }
|
54 |
|
55 | const original = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
56 | Object.defineProperty(jasmine, 'DEFAULT_TIMEOUT_INTERVAL', {
|
57 | configurable: true,
|
58 | enumerable: true,
|
59 | get: () => original,
|
60 | set
|
61 | });
|
62 | }
|
63 |
|
64 | function throwAtFunction(message, fn) {
|
65 | throw new _jestUtil.ErrorWithStack(message, fn);
|
66 | }
|