-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Rework the .toMatch()
matcher
#168
Comments
Transition to different behaviour would be smoother, if matcher would be renamed. I mean, it is bette to add new matcher and to deprecate
expect({ foo: "bar", hello: "universe" }).type.toInclude({ foo: "bar" });
expect({ foo: "bar", hello: "universe" }).type.not.toInclude({ baz: 123 });
expect<{ foo: string; bar: number }>().type.toInclude<{ foo: string }>();
expect<{ foo: string; bar: number }>().type.not.toInclude<{ baz: number }>();
expect({ foo: "bar", hello: "universe" }).type.toContain({ foo: "bar" });
expect({ foo: "bar", hello: "universe" }).type.not.toContain({ baz: 123 });
expect<{ foo: string; bar: number }>().type.toContain<{ foo: string }>();
expect<{ foo: string; bar: number }>().type.not.toContain<{ baz: number }>(); |
Another idea, expect<[foo: string, bar: number]>().type.toContain<[foo: string]>();
expect<[foo: string, bar: number]>().type.not.toContain<[baz: number]>();
// otherwise errors with: Type '[foo: string, bar: number]' does not contain element of type 'number'
expect<Array<string | number>>().type.toContain<Array<number>>();
expect<Array<string | number>>().type.not.toContain<Array<boolean>>();
// otherwise errors with: Type 'string | number' does not contain type 'boolean' First TSTyche should check that objects / tuples / arrays are on both sides. If these are:
|
Also union types could be compared: expect<Array<string> | Array<number>>().type.toContain<Array<string>>();
expect<string | number>().type.toContain<string>();
expect<string | number>().type.not.toContain<boolean>();
// otherwise errors with: Type 'string | number' does not contain type 'boolean' |
And perhaps even intersections (more complex, but interesting!): expect<{ a: number } & { b: string } & { c: string }>().type.toContain<{ b: string } & { c: string }>();
expect<{ a: number } & { b: string } & { c: string }>().type.not.toContain<{ b: string } & { c: boolean }>();
// otherwise errors with: Type '{ a: number } & { b: string } & { c: string }' does not contain type '{ b: string } & { c: boolean }' |
If this new matcher would work only on objects, |
It makes sense to rethink and rework the behaviour of the
.toMatch()
matcher. Looking at feedback (#167) and usage it should:.toHaveProperty()
on all properties);.toBe()
on all properties).In other words, its behaviour must be similar to the
.toMatchObject()
matcher found in theexpect
library. Without any subtype checks.The subtype checks are useful, but it would be better to implement them separately as new
.toBeSubtypeOf()
and.toBeSupertypeOf()
matchers.The text was updated successfully, but these errors were encountered: