Skip to content

Commit f6d812c

Browse files
committed
Remove nested describe block from createAction.test-d.tsx
- Resolved an issue where the type checker in Vitest hangs when handling three levels of nested `describe` blocks. vitest-dev/vitest#4964
1 parent 7713856 commit f6d812c

File tree

1 file changed

+125
-130
lines changed

1 file changed

+125
-130
lines changed

packages/toolkit/src/tests/createAction.test-d.tsx

Lines changed: 125 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -97,194 +97,189 @@ describe('type tests', () => {
9797
})
9898
})
9999

100-
describe('createAction()', () => {
101-
test('createAction() has type parameter for the action payload.', () => {
102-
const increment = createAction<number, 'increment'>('increment')
100+
test('createAction() has type parameter for the action payload.', () => {
101+
const increment = createAction<number, 'increment'>('increment')
103102

104-
expectTypeOf(increment).parameter(0).toBeNumber()
103+
expectTypeOf(increment).parameter(0).toBeNumber()
105104

106-
expectTypeOf(increment).parameter(0).not.toBeString()
107-
})
105+
expectTypeOf(increment).parameter(0).not.toBeString()
106+
})
108107

109-
test('createAction() type parameter is required, not inferred (defaults to `void`).', () => {
110-
const increment = createAction('increment')
108+
test('createAction() type parameter is required, not inferred (defaults to `void`).', () => {
109+
const increment = createAction('increment')
111110

112-
expectTypeOf(increment).parameter(0).not.toBeNumber()
111+
expectTypeOf(increment).parameter(0).not.toBeNumber()
113112

114-
expectTypeOf(increment().payload).not.toBeNumber()
115-
})
113+
expectTypeOf(increment().payload).not.toBeNumber()
114+
})
116115

117-
test('createAction().type is a string literal.', () => {
118-
const increment = createAction<number, 'increment'>('increment')
116+
test('createAction().type is a string literal.', () => {
117+
const increment = createAction<number, 'increment'>('increment')
119118

120-
expectTypeOf(increment(1).type).toBeString()
119+
expectTypeOf(increment(1).type).toBeString()
121120

122-
expectTypeOf(increment(1).type).toEqualTypeOf<'increment'>()
121+
expectTypeOf(increment(1).type).toEqualTypeOf<'increment'>()
123122

124-
expectTypeOf(increment(1).type).not.toMatchTypeOf<'other'>()
123+
expectTypeOf(increment(1).type).not.toMatchTypeOf<'other'>()
125124

126-
expectTypeOf(increment(1).type).not.toBeNumber()
127-
})
125+
expectTypeOf(increment(1).type).not.toBeNumber()
126+
})
128127

129-
test('type still present when using prepareAction', () => {
130-
const strLenAction = createAction('strLen', (payload: string) => ({
131-
payload: payload.length,
132-
}))
128+
test('type still present when using prepareAction', () => {
129+
const strLenAction = createAction('strLen', (payload: string) => ({
130+
payload: payload.length,
131+
}))
133132

134-
expectTypeOf(strLenAction('test').type).toBeString()
135-
})
133+
expectTypeOf(strLenAction('test').type).toBeString()
134+
})
136135

137-
test('changing payload type with prepareAction', () => {
138-
const strLenAction = createAction('strLen', (payload: string) => ({
139-
payload: payload.length,
140-
}))
136+
test('changing payload type with prepareAction', () => {
137+
const strLenAction = createAction('strLen', (payload: string) => ({
138+
payload: payload.length,
139+
}))
141140

142-
expectTypeOf(strLenAction('test').payload).toBeNumber()
141+
expectTypeOf(strLenAction('test').payload).toBeNumber()
143142

144-
expectTypeOf(strLenAction('test').payload).not.toBeString()
143+
expectTypeOf(strLenAction('test').payload).not.toBeString()
145144

146-
expectTypeOf(strLenAction('test')).not.toHaveProperty('error')
147-
})
145+
expectTypeOf(strLenAction('test')).not.toHaveProperty('error')
146+
})
148147

149-
test('adding metadata with prepareAction', () => {
150-
const strLenMetaAction = createAction(
151-
'strLenMeta',
152-
(payload: string) => ({
153-
payload,
154-
meta: payload.length,
155-
}),
156-
)
148+
test('adding metadata with prepareAction', () => {
149+
const strLenMetaAction = createAction('strLenMeta', (payload: string) => ({
150+
payload,
151+
meta: payload.length,
152+
}))
157153

158-
expectTypeOf(strLenMetaAction('test').meta).toBeNumber()
154+
expectTypeOf(strLenMetaAction('test').meta).toBeNumber()
159155

160-
expectTypeOf(strLenMetaAction('test').meta).not.toBeString()
156+
expectTypeOf(strLenMetaAction('test').meta).not.toBeString()
161157

162-
expectTypeOf(strLenMetaAction('test')).not.toHaveProperty('error')
163-
})
158+
expectTypeOf(strLenMetaAction('test')).not.toHaveProperty('error')
159+
})
164160

165-
test('adding boolean error with prepareAction', () => {
166-
const boolErrorAction = createAction('boolError', (payload: string) => ({
167-
payload,
168-
error: true,
169-
}))
161+
test('adding boolean error with prepareAction', () => {
162+
const boolErrorAction = createAction('boolError', (payload: string) => ({
163+
payload,
164+
error: true,
165+
}))
170166

171-
expectTypeOf(boolErrorAction('test').error).toBeBoolean()
167+
expectTypeOf(boolErrorAction('test').error).toBeBoolean()
172168

173-
expectTypeOf(boolErrorAction('test').error).not.toBeString()
174-
})
169+
expectTypeOf(boolErrorAction('test').error).not.toBeString()
170+
})
175171

176-
test('adding string error with prepareAction', () => {
177-
const strErrorAction = createAction('strError', (payload: string) => ({
178-
payload,
179-
error: 'this is an error',
180-
}))
172+
test('adding string error with prepareAction', () => {
173+
const strErrorAction = createAction('strError', (payload: string) => ({
174+
payload,
175+
error: 'this is an error',
176+
}))
181177

182-
expectTypeOf(strErrorAction('test').error).toBeString()
178+
expectTypeOf(strErrorAction('test').error).toBeString()
183179

184-
expectTypeOf(strErrorAction('test').error).not.toBeBoolean()
185-
})
180+
expectTypeOf(strErrorAction('test').error).not.toBeBoolean()
181+
})
186182

187-
test('regression test for https://github.com/reduxjs/redux-toolkit/issues/214', () => {
188-
const action = createAction<{ input?: string }>('ACTION')
183+
test('regression test for https://github.com/reduxjs/redux-toolkit/issues/214', () => {
184+
const action = createAction<{ input?: string }>('ACTION')
189185

190-
expectTypeOf(action({ input: '' }).payload.input).toEqualTypeOf<
191-
string | undefined
192-
>()
186+
expectTypeOf(action({ input: '' }).payload.input).toEqualTypeOf<
187+
string | undefined
188+
>()
193189

194-
expectTypeOf(action({ input: '' }).payload.input).not.toBeNumber()
190+
expectTypeOf(action({ input: '' }).payload.input).not.toBeNumber()
195191

196-
expectTypeOf(action).parameter(0).not.toMatchTypeOf({ input: 3 })
197-
})
192+
expectTypeOf(action).parameter(0).not.toMatchTypeOf({ input: 3 })
193+
})
198194

199-
test('regression test for https://github.com/reduxjs/redux-toolkit/issues/224', () => {
200-
const oops = createAction('oops', (x: any) => ({
201-
payload: x,
202-
error: x,
203-
meta: x,
204-
}))
195+
test('regression test for https://github.com/reduxjs/redux-toolkit/issues/224', () => {
196+
const oops = createAction('oops', (x: any) => ({
197+
payload: x,
198+
error: x,
199+
meta: x,
200+
}))
205201

206-
expectTypeOf(oops('').payload).toBeAny()
202+
expectTypeOf(oops('').payload).toBeAny()
207203

208-
expectTypeOf(oops('').error).toBeAny()
204+
expectTypeOf(oops('').error).toBeAny()
209205

210-
expectTypeOf(oops('').meta).toBeAny()
211-
})
206+
expectTypeOf(oops('').meta).toBeAny()
207+
})
212208

213-
describe('createAction.match()', () => {
214-
test('simple use case', () => {
215-
const actionCreator = createAction<string, 'test'>('test')
209+
describe('createAction.match()', () => {
210+
test('simple use case', () => {
211+
const actionCreator = createAction<string, 'test'>('test')
216212

217-
const x: Action<string> = {} as any
213+
const x: Action<string> = {} as any
218214

219-
if (actionCreator.match(x)) {
220-
expectTypeOf(x.type).toEqualTypeOf<'test'>()
215+
if (actionCreator.match(x)) {
216+
expectTypeOf(x.type).toEqualTypeOf<'test'>()
221217

222-
expectTypeOf(x.payload).toBeString()
223-
} else {
224-
expectTypeOf(x.type).not.toMatchTypeOf<'test'>()
218+
expectTypeOf(x.payload).toBeString()
219+
} else {
220+
expectTypeOf(x.type).not.toMatchTypeOf<'test'>()
225221

226-
expectTypeOf(x).not.toHaveProperty('payload')
227-
}
228-
})
222+
expectTypeOf(x).not.toHaveProperty('payload')
223+
}
224+
})
229225

230-
test('special case: optional argument', () => {
231-
const actionCreator = createAction<string | undefined, 'test'>('test')
226+
test('special case: optional argument', () => {
227+
const actionCreator = createAction<string | undefined, 'test'>('test')
232228

233-
const x: Action<string> = {} as any
229+
const x: Action<string> = {} as any
234230

235-
if (actionCreator.match(x)) {
236-
expectTypeOf(x.type).toEqualTypeOf<'test'>()
231+
if (actionCreator.match(x)) {
232+
expectTypeOf(x.type).toEqualTypeOf<'test'>()
237233

238-
expectTypeOf(x.payload).toEqualTypeOf<string | undefined>()
239-
}
240-
})
234+
expectTypeOf(x.payload).toEqualTypeOf<string | undefined>()
235+
}
236+
})
241237

242-
test('special case: without argument', () => {
243-
const actionCreator = createAction('test')
238+
test('special case: without argument', () => {
239+
const actionCreator = createAction('test')
244240

245-
const x: Action<string> = {} as any
241+
const x: Action<string> = {} as any
246242

247-
if (actionCreator.match(x)) {
248-
expectTypeOf(x.type).toEqualTypeOf<'test'>()
243+
if (actionCreator.match(x)) {
244+
expectTypeOf(x.type).toEqualTypeOf<'test'>()
249245

250-
expectTypeOf(x.payload).not.toMatchTypeOf<{}>()
251-
}
252-
})
246+
expectTypeOf(x.payload).not.toMatchTypeOf<{}>()
247+
}
248+
})
253249

254-
test('special case: with prepareAction', () => {
255-
const actionCreator = createAction('test', () => ({
256-
payload: '',
257-
meta: '',
258-
error: false,
259-
}))
250+
test('special case: with prepareAction', () => {
251+
const actionCreator = createAction('test', () => ({
252+
payload: '',
253+
meta: '',
254+
error: false,
255+
}))
260256

261-
const x: Action<string> = {} as any
257+
const x: Action<string> = {} as any
262258

263-
if (actionCreator.match(x)) {
264-
expectTypeOf(x.type).toEqualTypeOf<'test'>()
259+
if (actionCreator.match(x)) {
260+
expectTypeOf(x.type).toEqualTypeOf<'test'>()
265261

266-
expectTypeOf(x.payload).toBeString()
262+
expectTypeOf(x.payload).toBeString()
267263

268-
expectTypeOf(x.meta).toBeString()
264+
expectTypeOf(x.meta).toBeString()
269265

270-
expectTypeOf(x.error).toBeBoolean()
266+
expectTypeOf(x.error).toBeBoolean()
271267

272-
expectTypeOf(x.payload).not.toBeNumber()
268+
expectTypeOf(x.payload).not.toBeNumber()
273269

274-
expectTypeOf(x.meta).not.toBeNumber()
270+
expectTypeOf(x.meta).not.toBeNumber()
275271

276-
expectTypeOf(x.error).not.toBeNumber()
277-
}
278-
})
279-
test('potential use: as array filter', () => {
280-
const actionCreator = createAction<string, 'test'>('test')
272+
expectTypeOf(x.error).not.toBeNumber()
273+
}
274+
})
275+
test('potential use: as array filter', () => {
276+
const actionCreator = createAction<string, 'test'>('test')
281277

282-
const x: Action<string>[] = []
278+
const x: Action<string>[] = []
283279

284-
expectTypeOf(x.filter(actionCreator.match)).toEqualTypeOf<
285-
PayloadAction<string, 'test'>[]
286-
>()
287-
})
280+
expectTypeOf(x.filter(actionCreator.match)).toEqualTypeOf<
281+
PayloadAction<string, 'test'>[]
282+
>()
288283
})
289284
})
290285

0 commit comments

Comments
 (0)