@samitouri / QOS-React / commits / 854c953905

Fix matcher tests to be DEV-only

Dan Abramov committed Jul 16, 2018 at 20:35 UTC 854c9539058834038b67a87a7146a1ec2a2ceeb6
1 file changed +101 -87
scripts/jest/matchers/__tests__/toWarnDev-test.js
+101 -87
@@ -12,126 +12,140 @@
12 describe('toWarnDev', () => {
13 it('does not fail if a warning contains a stack', () => {
14 expect(() => {
15 - console.error('Hello\n in div');
15 + if (__DEV__) {
16 + console.error('Hello\n in div');
17 + }
18 }).toWarnDev('Hello');
19 });
20
21 it('does not fail if all warnings contain a stack', () => {
22 expect(() => {
21 - console.error('Hello\n in div');
22 - console.error('Good day\n in div');
23 - console.error('Bye\n in div');
23 + if (__DEV__) {
24 + console.error('Hello\n in div');
25 + console.error('Good day\n in div');
26 + console.error('Bye\n in div');
27 + }
28 }).toWarnDev(['Hello', 'Good day', 'Bye']);
29 });
30
31 it('does not fail if warnings without stack explicitly opt out', () => {
32 expect(() => {
29 - console.error('Hello');
33 + if (__DEV__) {
34 + console.error('Hello');
35 + }
36 }).toWarnDev('Hello', {withoutStack: true});
37 expect(() => {
32 - console.error('Hello');
33 - console.error('Good day');
34 - console.error('Bye');
38 + if (__DEV__) {
39 + console.error('Hello');
40 + console.error('Good day');
41 + console.error('Bye');
42 + }
43 }).toWarnDev(['Hello', 'Good day', 'Bye'], {withoutStack: true});
44 });
45
46 it('does not fail when expected stack-less warning number matches the actual one', () => {
47 expect(() => {
40 - console.error('Hello\n in div');
41 - console.error('Good day');
42 - console.error('Bye\n in div');
48 + if (__DEV__) {
49 + console.error('Hello\n in div');
50 + console.error('Good day');
51 + console.error('Bye\n in div');
52 + }
53 }).toWarnDev(['Hello', 'Good day', 'Bye'], {withoutStack: 1});
54 });
55
46 - it('fails if a warning does not contain a stack', () => {
47 - expect(() => {
56 + if (__DEV__) {
57 + it('fails if a warning does not contain a stack', () => {
58 expect(() => {
49 - console.error('Hello');
50 - }).toWarnDev('Hello');
51 - }).toThrow(
52 - 'Received warning unexpectedly does not include a component stack'
53 - );
54 - });
59 + expect(() => {
60 + console.error('Hello');
61 + }).toWarnDev('Hello');
62 + }).toThrow(
63 + 'Received warning unexpectedly does not include a component stack'
64 + );
65 + });
66
56 - it('fails if some warnings do not contain a stack', () => {
57 - expect(() => {
67 + it('fails if some warnings do not contain a stack', () => {
68 expect(() => {
59 - console.error('Hello\n in div');
60 - console.error('Good day\n in div');
61 - console.error('Bye');
62 - }).toWarnDev(['Hello', 'Good day', 'Bye']);
63 - }).toThrow(
64 - 'Received warning unexpectedly does not include a component stack'
65 - );
66 - expect(() => {
69 + expect(() => {
70 + console.error('Hello\n in div');
71 + console.error('Good day\n in div');
72 + console.error('Bye');
73 + }).toWarnDev(['Hello', 'Good day', 'Bye']);
74 + }).toThrow(
75 + 'Received warning unexpectedly does not include a component stack'
76 + );
77 expect(() => {
68 - console.error('Hello');
69 - console.error('Good day\n in div');
70 - console.error('Bye\n in div');
71 - }).toWarnDev(['Hello', 'Good day', 'Bye']);
72 - }).toThrow(
73 - 'Received warning unexpectedly does not include a component stack'
74 - );
75 - expect(() => {
78 + expect(() => {
79 + console.error('Hello');
80 + console.error('Good day\n in div');
81 + console.error('Bye\n in div');
82 + }).toWarnDev(['Hello', 'Good day', 'Bye']);
83 + }).toThrow(
84 + 'Received warning unexpectedly does not include a component stack'
85 + );
86 expect(() => {
77 - console.error('Hello\n in div');
78 - console.error('Good day');
79 - console.error('Bye\n in div');
80 - }).toWarnDev(['Hello', 'Good day', 'Bye']);
81 - }).toThrow(
82 - 'Received warning unexpectedly does not include a component stack'
83 - );
84 - expect(() => {
87 + expect(() => {
88 + console.error('Hello\n in div');
89 + console.error('Good day');
90 + console.error('Bye\n in div');
91 + }).toWarnDev(['Hello', 'Good day', 'Bye']);
92 + }).toThrow(
93 + 'Received warning unexpectedly does not include a component stack'
94 + );
95 expect(() => {
86 - console.error('Hello');
87 - console.error('Good day');
88 - console.error('Bye');
89 - }).toWarnDev(['Hello', 'Good day', 'Bye']);
90 - }).toThrow(
91 - 'Received warning unexpectedly does not include a component stack'
92 - );
93 - });
96 + expect(() => {
97 + console.error('Hello');
98 + console.error('Good day');
99 + console.error('Bye');
100 + }).toWarnDev(['Hello', 'Good day', 'Bye']);
101 + }).toThrow(
102 + 'Received warning unexpectedly does not include a component stack'
103 + );
104 + });
105
95 - it('fails if warning is expected to not have a stack, but does', () => {
96 - expect(() => {
106 + it('fails if warning is expected to not have a stack, but does', () => {
107 expect(() => {
98 - console.error('Hello\n in div');
99 - }).toWarnDev('Hello', {withoutStack: true});
100 - }).toThrow('Received warning unexpectedly includes a component stack');
101 - expect(() => {
108 + expect(() => {
109 + console.error('Hello\n in div');
110 + }).toWarnDev('Hello', {withoutStack: true});
111 + }).toThrow('Received warning unexpectedly includes a component stack');
112 expect(() => {
103 - console.error('Hello\n in div');
104 - console.error('Good day');
105 - console.error('Bye\n in div');
106 - }).toWarnDev(['Hello', 'Good day', 'Bye'], {withoutStack: true});
107 - }).toThrow('Received warning unexpectedly includes a component stack');
108 - });
113 + expect(() => {
114 + console.error('Hello\n in div');
115 + console.error('Good day');
116 + console.error('Bye\n in div');
117 + }).toWarnDev(['Hello', 'Good day', 'Bye'], {withoutStack: true});
118 + }).toThrow('Received warning unexpectedly includes a component stack');
119 + });
120
110 - it('fails if expected stack-less warning number does not match the actual one', () => {
111 - expect(() => {
121 + it('fails if expected stack-less warning number does not match the actual one', () => {
122 expect(() => {
113 - console.error('Hello\n in div');
114 - console.error('Good day');
115 - console.error('Bye\n in div');
116 - }).toWarnDev(['Hello', 'Good day', 'Bye'], {withoutStack: 4});
117 - }).toThrow('Expected 4 warnings without a component stack but received 1');
118 - });
123 + expect(() => {
124 + console.error('Hello\n in div');
125 + console.error('Good day');
126 + console.error('Bye\n in div');
127 + }).toWarnDev(['Hello', 'Good day', 'Bye'], {withoutStack: 4});
128 + }).toThrow(
129 + 'Expected 4 warnings without a component stack but received 1'
130 + );
131 + });
132
120 - it('fails if withoutStack is invalid', () => {
121 - expect(() => {
133 + it('fails if withoutStack is invalid', () => {
134 expect(() => {
123 - console.error('Hi');
124 - }).toWarnDev('Hi', {withoutStack: null});
125 - }).toThrow('Instead received object');
126 - expect(() => {
135 + expect(() => {
136 + console.error('Hi');
137 + }).toWarnDev('Hi', {withoutStack: null});
138 + }).toThrow('Instead received object');
139 expect(() => {
128 - console.error('Hi');
129 - }).toWarnDev('Hi', {withoutStack: {}});
130 - }).toThrow('Instead received object');
131 - expect(() => {
140 + expect(() => {
141 + console.error('Hi');
142 + }).toWarnDev('Hi', {withoutStack: {}});
143 + }).toThrow('Instead received object');
144 expect(() => {
133 - console.error('Hi');
134 - }).toWarnDev('Hi', {withoutStack: 'haha'});
135 - }).toThrow('Instead received string');
136 - });
145 + expect(() => {
146 + console.error('Hi');
147 + }).toWarnDev('Hi', {withoutStack: 'haha'});
148 + }).toThrow('Instead received string');
149 + });
150 + }
151 });