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 - JavaScript Tutorial
From the course: JavaScript: Test-Driven Development (ES6)
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Testing database communication: Basic setup3m 49s
-
(Locked)
Database setup and teardown in tests5m 22s
-
(Locked)
Ignoring object properties in Mocha3m 7s
-
(Locked)
Using environment variables in testing2m 29s
-
(Locked)
Creating test helpers5m 9s
-
(Locked)
Resetting the database between tests2m 12s
-
(Locked)
-
-
-