Create a NodeJS API with Koa and TypeScript - #6 - Testing With Jest

preview_player
Показать описание
Before going much further, bringing Jest / testing in to the mix is a good idea. Start off early with testing, and you (or I) am much more likely to continue with it throughout the rest of the project. If you add in tests as an after thought, some of the risks include:

not fully testing your code
not completely trusting the tests
not building the habit of writing tests

That's just some. There are tons of downsides to not testing, and very few upsides. Having worked on plenty of large, real world projects without tests, let me tell you: it sucks.

Enough of the testing soapbox.

We have already added jest to our project in the initial project setup.

Рекомендации по теме
Комментарии
Автор

Hi,

How can I set jest test to run modules instead of __test__

e.g

akhamagaqana
Автор

importing request can also be done this way: import * as request from 'supertest'

CatMeowMeow
Автор

Wish there would be some code to check with mine. Any repo>?

skryonline
Автор

afterEach(done =>{
server.close();
done();
})

This code is actually not safe - at least it wasnt for me. This threw Address already in use, as server.close takes a bit. Pass done as callback into server.close to make it work properly.

server.close(done);

leumasme
welcome to shbcf.ru