2 jest testing typescript

illustrate

We can already use jest to unit test js, but currently the more popular one is ts, so how do we use jest to test ts?
The official website gives two methods:
1. Use babel+typescript to compile and test (this method requires a lot of configuration, and several files need to be updated simultaneously during the update. So it is not recommended) 2. Use jest
directly Integration package @types/jest, but it should also be explained here
*@types/jest是在DefinitelyTyped中维护的第三方库,因此可能还没有涵盖最新的jest特性或版本。尽量匹配Jest和@types/ Jest的版本。例如,如果你使用的是Jest 27.4.0,那么就安装27.4。@types/jest的X是理想的*

1 Install @types/jest

Insert image description here

2 tests

Insert image description here
Of course, we can also test the writing method of class class, which also satisfies cmd
Insert image description here

Guess you like

Origin blog.csdn.net/wangbiao9292/article/details/129278159