Skip to content

Test Typings logs

xXAlphaManXx edited this page Jun 22, 2020 · 2 revisions

Test Typings

What?

Jest currently only runs the test cases but doesn't check the typings of the test functions itself. Eg: if a function is add(a: number, b: number) and but is invoked with add(1, '2') we should induce type checking to actually report that as an error (test fail in this case)

How?

There are many libraries already which do type checkings

All we need to probably do is make a custom runner in jest that imports any one of the above mentioned libraries. We also need to make the assertions method public which can be done by leveraging global APIs available in jest (TODO: add references to the docs)

Thoughts:

I think it would be better to use DTSLint because it's maintained by Microsoft itself. Thus making sure it has future support and wide community for support. TSD is by no means not good. Just that the project seems to be a little left off.

Problems

  1. DTSLint, by a quick glance at it, probably doesn't support programmatic invoking. It could be available. I just didn't research that long yet.

Solutions

  1. For the first problem
    • We can either make a seperate process that runs the NPM commands and then parses data (more work, not perfomant)
    • Or we can hack through the library, run functions manually. (future support would be hard if the API changes on the library's side)

References

Clone this wiki locally