Open everett1992 opened 1 year ago
I think it's caused by this line
and it appears to be fixed by changing it to
(name: string, fn?: TestFunction<ExtraContext>, options?: number | TestOptions): void
But I'm not sure if that has other downsides.
This issue appears to affect it.for
in the same way.
// Referencing the example context by OP, `now` exists and can be used but TypeScript does not see the extended context
it.for<{ b: boolean }>([{ b: true }, { b: false }])("it should", ({ b }, { now }) => {...})
Given that it<Context>
works, one would expect this to work but it doesn't it.for<ForType>([ ... ])<Context>("it should", () => {})
. The function called on each for
doesn't accept a T generic.
This could be some limitation on typescript's it<Context>
expression.
Instead of it<Context>
, using it as CustomAPI<Context>
seems to work better. I guess understanding this difference would require a solid typescript hacker.
https://stackblitz.com/edit/vitest-dev-vitest-mvn39n?file=test%2Fcontext.test.ts
import { it } from 'vitest';
import type { CustomAPI } from '@vitest/runner';
// const cit = it<{ now: Date }>;
const cit = it as CustomAPI<{ now: Date }>;
cit('', ({ now }) => {
now satisfies Date;
});
cit.skip('', ({ now }) => {
now satisfies Date;
});
Describe the bug
Chaining methods reset ExtraContext to
{}
.it<Context>.skip
will use{}
instead ofContext
. Whileit.skip<Context>
will work it's not as ergonomic asit<Context>.skip
especially when assigning a context'ed it to a variable for reuse.Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-pwreuv?file=test/context.test.ts
System Info
Used Package Manager
npm
Validations