jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.27k stars 6.47k forks source link

Setup test suite for type definitions #8794

Closed SimenB closed 4 years ago

SimenB commented 5 years ago

Jest is written in TypeScript, but that doesn't mean that the different APIs Jest injects into a test are particularly well typed. Having good type tests for expect and the different methods available on the jest object (jest.spyOn, jest.mock etc) would be great to assert that they provide the DX they should. Especially since we hope to include global typings with Jest 25, we should ensure we are safe to move quickly if they are painful for people coming from the DefinitelyTyped types. Especially assertions that invalid things are reported as type errors would be great.

Current test suite in DT: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/jest/jest-tests.ts

I'm not sure what tool would be best for this, but something like https://github.com/microsoft/dtslint or https://github.com/SamVerschueren/tsd maybe? It should run as part of Jest's test suite, so we need a custom runner for them (or some other tool that does the same job).

This runner could then of course be used by other people who want to test their type defs, and run those tests with Jest.

/cc @orta if you have any thoughts you wanna share on this

orta commented 5 years ago

We chatted in discord: I feel like tsd is a good spot for this and there are techniques like const a: import("jest").Expect which would allow types to be passed around internally without too much churn.

jevakallio commented 4 years ago

Working with @MLH-fellowship on this, summarising some of the internal fact-finding here.

Solution

Requirements:

Ideal solution:

raijinsetsu commented 4 years ago

This seems huge for making sure that public APIs do not change across versions and that expectations of how Typescript resolves the types remains true.

I am able to use the expectType functions (those work without any Jest changes) but the expectError and similar just will not. I also have to mock up the implementation because, unlike when it's run under "tsd", running the tests under Jest DOES mean that the code will be executed and that means that it must, at least, not throw an error.

SimenB commented 4 years ago

This landed in #10407. While we don't test that much yet, the infrastructure is now in place 🎉

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.