-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Closed
Labels
Description
Can the matcher/assertion functions be generic and typesafe as in Jasmine?: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/jasmine/v3/index.d.ts#L792. There is also a ticket for this at Jest: jestjs/jest#13334 and jestjs/jest#13444 (review).
expect(true).toBe('') // type error: the expect prop type is not equal to the matcher prop typeThis might also be useful for API testing:
// ProductDto.ts
export type ProductDto = {
id: string;
name: string;
}import { ProductDto } from '@shared-package';
test('API response matches the ProductDto', async ({ request: http }) => {
const response = await http.get<ProductDto>('/product/1337');
const data = await response.json(); // data is typeof ProductDto
expect(data).toEqual({ id: 1337, name: 'John' }); // error property 'id' is not a string
});