1
'use strict';
2
3
-require('./setupMocks');
3
+if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
4
+ // Inside the class equivalence tester, we have a custom environment, let's
5
+ // require that instead.
6
+ require('./setupSpecEquivalenceReporter.js');
7
+} else {
8
+ var env = jasmine.getEnv();
9
5
-var env = jasmine.getEnv();
6
-
7
-var callCount = 0;
8
-var oldError = console.error;
9
-var newError = function() {
10
- callCount++;
11
- oldError.apply(this, arguments);
12
-};
10
+ var callCount = 0;
11
+ var oldError = console.error;
12
+ var newError = function() {
13
+ callCount++;
14
+ oldError.apply(this, arguments);
15
+ };
16
14
-console.error = newError;
17
+ console.error = newError;
18
16
-// TODO: Stop using spyOn in all the test since that seem deprecated.
17
-// Legacy upgrade path from https://github.com/facebook/jest/blob/21a2b7aaee366af7ed87ae78c5b2d58cf3f5fb86/packages/jest-matchers/src/spy_matchers.js#L160
18
-const isSpy = spy => spy.calls && typeof spy.calls.count === 'function';
19
+ // TODO: Stop using spyOn in all the test since that seem deprecated.
20
+ // Legacy upgrade path from https://github.com/facebook/jest/blob/21a2b7aaee366af7ed87ae78c5b2d58cf3f5fb86/packages/jest-matchers/src/spy_matchers.js#L160
21
+ const isSpy = spy => spy.calls && typeof spy.calls.count === 'function';
22
20
-env.beforeEach(() => {
21
- callCount = 0;
22
- jasmine.addMatchers({
23
- toBeReset() {
24
- return {
25
- compare(actual) {
26
- // TODO: Catch test cases that call spyOn() but don't inspect the mock
27
- // properly.
28
- if (actual !== newError && !isSpy(actual)) {
23
+ env.beforeEach(() => {
24
+ callCount = 0;
25
+ jasmine.addMatchers({
26
+ toBeReset() {
27
+ return {
28
+ compare(actual) {
29
+ // TODO: Catch test cases that call spyOn() but don't inspect the mock
30
+ // properly.
31
+ if (actual !== newError && !isSpy(actual)) {
32
+ return {
33
+ pass: false,
34
+ message: () =>
35
+ 'Test did not tear down console.error mock properly.',
36
+ };
37
+ }
38
+ return {pass: true};
39
+ },
40
+ };
41
+ },
42
+ toNotHaveBeenCalled() {
43
+ return {
44
+ compare(actual) {
45
return {
30
- pass: false,
46
+ pass: callCount === 0,
47
message: () =>
32
- 'Test did not tear down console.error mock properly.',
48
+ 'Expected test not to warn. If the warning is expected, mock ' +
49
+ "it out using spyOn(console, 'error'); and test that the " +
50
+ 'warning occurs.',
51
};
34
- }
35
- return {pass: true};
36
- },
37
- };
38
- },
39
- toNotHaveBeenCalled() {
40
- return {
41
- compare(actual) {
42
- return {
43
- pass: callCount === 0,
44
- message: () =>
45
- 'Expected test not to warn. If the warning is expected, mock ' +
46
- "it out using spyOn(console, 'error'); and test that the " +
47
- 'warning occurs.',
48
- };
49
- },
50
- };
51
- },
52
+ },
53
+ };
54
+ },
55
+ });
56
+ });
57
+ env.afterEach(() => {
58
+ expect(console.error).toBeReset();
59
+ expect(console.error).toNotHaveBeenCalled();
60
});
53
-});
54
-env.afterEach(() => {
55
- expect(console.error).toBeReset();
56
- expect(console.error).toNotHaveBeenCalled();
57
-});
61
59
-function wrapDevMatcher(obj, name) {
60
- const original = obj[name];
61
- obj[name] = function devMatcher() {
62
- try {
63
- original.apply(this, arguments);
64
- } catch (e) {
65
- global.__hadDevFailures = e.stack;
62
+ function wrapDevMatcher(obj, name) {
63
+ const original = obj[name];
64
+ obj[name] = function devMatcher() {
65
+ try {
66
+ original.apply(this, arguments);
67
+ } catch (e) {
68
+ global.__hadDevFailures = e.stack;
69
+ }
70
+ };
71
+ }
72
+
73
+ const expectDev = function expectDev(actual) {
74
+ const expectation = expect(actual);
75
+ if (global.__suppressDevFailures) {
76
+ Object.keys(expectation).forEach(name => {
77
+ wrapDevMatcher(expectation, name);
78
+ wrapDevMatcher(expectation.not, name);
79
+ });
80
}
81
+ return expectation;
82
};
83
+ global.expectDev = expectDev;
84
}
69
-
70
-const expectDev = function expectDev(actual) {
71
- const expectation = expect(actual);
72
- if (global.__suppressDevFailures) {
73
- Object.keys(expectation).forEach(name => {
74
- wrapDevMatcher(expectation, name);
75
- wrapDevMatcher(expectation.not, name);
76
- });
77
- }
78
- return expectation;
79
-};
80
-global.expectDev = expectDev;