|
1 | 1 | import wait from 'wait'; |
2 | 2 |
|
3 | | -import itWithContext from '../../../../testUtils/itWithContext'; |
4 | | - |
5 | 3 | import VestTest from 'VestTest'; |
6 | | -import { useAllIncomplete, useTestObjects } from 'stateHooks'; |
| 4 | +import { useAllIncomplete } from 'stateHooks'; |
7 | 5 | import * as vest from 'vest'; |
8 | 6 |
|
9 | 7 | const fieldName = 'unicycle'; |
@@ -92,57 +90,78 @@ describe('VestTest', () => { |
92 | 90 | }); |
93 | 91 | }); |
94 | 92 |
|
95 | | - itWithContext('Should be removed from the list of incomplete tests', () => { |
96 | | - const [, setTestObjects] = useTestObjects(); |
97 | | - setTestObjects(({ prev, current }) => ({ |
98 | | - prev, |
99 | | - current: current.concat(testObject), |
100 | | - })); |
101 | | - testObject.setPending(); |
102 | | - { |
103 | | - const allIncomplete = useAllIncomplete(); |
104 | | - |
105 | | - expect(allIncomplete).toEqual(expect.arrayContaining([testObject])); |
106 | | - } |
107 | | - testObject.cancel(); |
108 | | - { |
109 | | - const allIncomplete = useAllIncomplete(); |
110 | | - expect(allIncomplete).toEqual(expect.not.arrayContaining([testObject])); |
111 | | - } |
| 93 | + it('Should be removed from the list of incomplete tests', () => { |
| 94 | + const control = jest.fn(); |
| 95 | + vest.create(() => { |
| 96 | + const testObject = vest.test('f1', async () => { |
| 97 | + await wait(100); |
| 98 | + }); |
| 99 | + |
| 100 | + expect(testObject.isPending()).toBe(true); |
| 101 | + { |
| 102 | + const allIncomplete = useAllIncomplete(); |
| 103 | + |
| 104 | + expect(allIncomplete).toEqual(expect.arrayContaining([testObject])); |
| 105 | + } |
| 106 | + testObject.cancel(); |
| 107 | + { |
| 108 | + const allIncomplete = useAllIncomplete(); |
| 109 | + expect(allIncomplete).toEqual( |
| 110 | + expect.not.arrayContaining([testObject]) |
| 111 | + ); |
| 112 | + } |
| 113 | + control(); |
| 114 | + })(); |
| 115 | + expect(control).toHaveBeenCalledTimes(1); |
112 | 116 | }); |
113 | 117 |
|
114 | 118 | describe('final statuses', () => { |
115 | | - let testObject, fn; |
| 119 | + let control; |
116 | 120 | beforeEach(() => { |
117 | | - fn = jest.fn(); |
118 | | - testObject = new VestTest('field', fn); |
| 121 | + control = jest.fn(); |
119 | 122 | }); |
120 | | - itWithContext('keep status unchanged when `failed`', () => { |
121 | | - testObject.fail(); |
122 | | - expect(testObject.isFailing()).toBe(true); |
123 | | - testObject.skip(); |
124 | | - expect(testObject.isSkipped()).toBe(false); |
125 | | - expect(testObject.isFailing()).toBe(true); |
126 | | - testObject.cancel(); |
127 | | - expect(testObject.isCanceled()).toBe(false); |
128 | | - expect(testObject.isFailing()).toBe(true); |
129 | | - testObject.setPending(); |
130 | | - expect(testObject.isPending()).toBe(false); |
131 | | - expect(testObject.isFailing()).toBe(true); |
| 123 | + it('keep status unchanged when `failed`', () => { |
| 124 | + vest.create(() => { |
| 125 | + // async so it is not a final status |
| 126 | + const testObject = vest.test('f1', async () => { |
| 127 | + await wait(100); |
| 128 | + }); |
| 129 | + testObject.fail(); |
| 130 | + expect(testObject.isFailing()).toBe(true); |
| 131 | + testObject.skip(); |
| 132 | + expect(testObject.isSkipped()).toBe(false); |
| 133 | + expect(testObject.isFailing()).toBe(true); |
| 134 | + testObject.cancel(); |
| 135 | + expect(testObject.isCanceled()).toBe(false); |
| 136 | + expect(testObject.isFailing()).toBe(true); |
| 137 | + testObject.setPending(); |
| 138 | + expect(testObject.isPending()).toBe(false); |
| 139 | + expect(testObject.isFailing()).toBe(true); |
| 140 | + control(); |
| 141 | + })(); |
| 142 | + expect(control).toHaveBeenCalledTimes(1); |
132 | 143 | }); |
133 | 144 |
|
134 | | - itWithContext('keep status unchanged when `canceled`', () => { |
135 | | - testObject.setStatus('CANCELED'); |
136 | | - expect(testObject.isCanceled()).toBe(true); |
137 | | - testObject.fail(); |
138 | | - expect(testObject.isCanceled()).toBe(true); |
139 | | - expect(testObject.isFailing()).toBe(false); |
140 | | - testObject.skip(); |
141 | | - expect(testObject.isSkipped()).toBe(false); |
142 | | - expect(testObject.isCanceled()).toBe(true); |
143 | | - testObject.setPending(); |
144 | | - expect(testObject.isPending()).toBe(false); |
145 | | - expect(testObject.isCanceled()).toBe(true); |
| 145 | + it('keep status unchanged when `canceled`', () => { |
| 146 | + vest.create(() => { |
| 147 | + // async so it is not a final status |
| 148 | + const testObject = vest.test('f1', async () => { |
| 149 | + await wait(100); |
| 150 | + }); |
| 151 | + testObject.setStatus('CANCELED'); |
| 152 | + expect(testObject.isCanceled()).toBe(true); |
| 153 | + testObject.fail(); |
| 154 | + expect(testObject.isCanceled()).toBe(true); |
| 155 | + expect(testObject.isFailing()).toBe(false); |
| 156 | + testObject.skip(); |
| 157 | + expect(testObject.isSkipped()).toBe(false); |
| 158 | + expect(testObject.isCanceled()).toBe(true); |
| 159 | + testObject.setPending(); |
| 160 | + expect(testObject.isPending()).toBe(false); |
| 161 | + expect(testObject.isCanceled()).toBe(true); |
| 162 | + control(); |
| 163 | + })(); |
| 164 | + expect(control).toHaveBeenCalledTimes(1); |
146 | 165 | }); |
147 | 166 | }); |
148 | 167 | }); |
|
0 commit comments