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

Unlock the full course today

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

Testing database communication: Basic setup

Testing database communication: Basic setup - JavaScript Tutorial

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

Start my 1-month free trial

Testing database communication: Basic setup

- [Instructor] So now that we've got our project set up correctly, let's start writing some tests. We're going to start off by testing and coding our database wrapper, since writing this first will allow us to create test doubles of it in the tests for the rest of our server. And you could really just create empty functions for these, create test doubles of those, and develop the rest of the server first, but I generally prefer to do it this way. So since we're going to be developing an endpoint that allows us to get a user by their user name, we're going to need to read from the database. So let's create a wrapper that does this. Let's import our currently non-existent function which we'll call get user by user name, import, get user by user name, from db, and we're also going to import expect. Import, expect from chai. We're going to start off our tests by writing a describe statement, and inside we'll say get user by…

Contents