I've built an API with hapi.js and sequelize (with Postgres), and now I'm creating the unit tests to check if everything is ok. I've created this test to check if GET on '/products' would return with the two products I create when I sync the table. Here is the test:test('Test get all products - GET /products', (t) => { const options = { method: 'GET', url: '/products', }; server.inject(options, (response) => { t.equal(response.statusCode, 200, 'Status Code = 200'); server.stop(t.end); }); }); For now it just checks if the server responds with HTTP code 200, but later I'll add to check if it's an array and if it's length is two. The problem is that the test is starting before the DB is synced, so it tries to access it before I declare the relations on my models. How can I wait to make sure the database was created, before testing?Here is the full code: http://ift.tt/2mjIw0y
Submitted March 13, 2017 at 04:25PM by Luke094
No comments:
Post a Comment