-
Notifications
You must be signed in to change notification settings - Fork 2
Testing our Node Express API
Alex Withington-Smith edited this page Jan 21, 2021
·
1 revision
We are using Supertest combined with Jest to test the functionality of our routes, with MongoMemoryServer as a mock MongoDB service that runs in RAM during the testing process.
A guide to how we set up Supertest can be found here, and the guide to how the memory server was set up for testing is here.
An example of how this looks for a POST request in practice is below:
it('Empty post request leads to the following errors', async () => {
const createAuthEmptyUser = await request.post('/api/auth');
let errors = createAuthEmptyUser.body.errors.map((e) => e.msg);
expect(errors.length).toEqual(2)
expect(errors).toContain('Please include a valid email')
expect(errors).toContain('Password is required')
});