-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
toBeBoolean
behaves differently from toEqualTypeOf<boolean>
#32
Comments
Yes, I agree, this should really be a |
Note: some nuance here. I think this applies to primitive, but I don't think it makes sense for The primitive case will be fixed in #16. |
Copy-pasted from docs added in #16, this will be the new behaviour:
expectTypeOf<number>().toBeNumber()
expectTypeOf<1>().toBeNumber()
expectTypeOf<any[]>().toBeArray()
expectTypeOf<number[]>().toBeArray()
expectTypeOf<string>().toBeString()
expectTypeOf<'foo'>().toBeString()
expectTypeOf<boolean>().toBeBoolean()
expectTypeOf<true>().toBeBoolean()
const goodIntParser = (s: string) => Number.parseInt(s, 10)
const badIntParser = (s: string) => JSON.parse(s) // uh-oh - works at runtime if the input is a number, but return 'any'
expectTypeOf(goodIntParser).returns.toBeNumber()
// @ts-expect-error - if you write a test like this, `.toBeNumber()` will let you know your implementation returns `any`.
expectTypeOf(badIntParser).returns.toBeNumber() Note that this is different from |
Playground link.
The first
expectTypeOf
passes (which it should not) but the second errs (correctly). They should both err.P.S. The same is true for other such helpers (like
toBeArray
, etc).The text was updated successfully, but these errors were encountered: