From the course: JavaScript: Test-Driven Development (ES6)

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Database setup and teardown in tests

Database setup and teardown in tests - JavaScript Tutorial

From the course: JavaScript: Test-Driven Development (ES6)

Start my 1-month free trial

Database setup and teardown in tests

- So now that we've got that boiler plate out of the way, our next step is to setup our test database for testing. Since we want to test that our get user by username function returns the correct user from our database. Let's setup our database with some dummy data, and see if our function performs correctly on that data. So we're going to create an array here that we're going to insert into the database, and it'll have some fake database data in it. So we'll say const fake data, and then I'm just going to paste this fake data, but you're more than welcome to get it from the exercise files. So we have two users that we're going to insert into the database, one that we want and one that we don't want. And we're going to check and make sure that our get user by username function gets the right one from the database. And actually inserting this data looks like this, we say await D-B dot collection users dot insert many fake data…

Contents