Skip to content

The test suite

Talysson de Oliveira Cassiano edited this page Mar 28, 2017 · 1 revision

The default test suite of the boilerplate uses Mocha as the testing framework and Chai for the assertions. They are located in the test folder in the root of the project and follow the same folder architecture as the src folder, except for the functional tests.

Inside the test/support folder there are some utilities that you can use during your tests, some of them are:

Database cleaning between tests

The ORM is already setup to clean the database before each it block, so your tests will be isolated from each other and can be run separately. To disable this behavior, comment the line with beforeEach(cleanDatabase) on the test setup file;

Factories

FactoryGirl library with the adapter for Sequelize is configurated so you can create records on your database in the setup phase of your tests. The factories are inside the test/support/factories folder of your app. Each factory file exports a function that receives two parameters: the FactoryGirl instance and the models of the database (located in the src/infra/database/models folder).

You can see an example of a factory being defined in the user factory and how to use it in the listUsers test.

Request to the web server and functional tests

Requests to the web server of the application can be done using the request helper. Internally it'll use supertest-as-promised passing your server instance and returning a promise that can be chained so you can do expectations about the response. Here's an example of how to do a GET request and expect it to return status 200 with empty response.