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.
To mock or not to mock? - JavaScript Tutorial
From the course: JavaScript: Test-Driven Development (ES6)
To mock or not to mock?
- Now that we've got our function working for both empty strings and simple strings, let's write a test to ensure that it works for more complicated strings with several occurrences of certain letters. Let's make another block for our test. And we're going to say that our function should return the correct letter count for words with more than one of certain letters. Now the string we're going to use to test this is the word Mississippi. M-I-S-S-I-S-S-I-P-P-I, which is the name of a river in the United States for those of you who don't know. So for our expected value, we're going to say const expected. And the word Mississippi has one m, four i's, four s's, and two p's. And for our actual value, we're going to say const actual = getLetterCount, Mississippi. And just like in our other tests, we're going to say that we expect the actual value to deep equal the expected value. So if we save this and then run our tests…
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
-
-
-
-
The purpose of unit testing3m 51s
-
(Locked)
JavaScript frameworks for unit testing2m 36s
-
(Locked)
Writing and running basic tests2m 8s
-
(Locked)
Testing basic functions5m 23s
-
(Locked)
Testing asynchronous functions3m 33s
-
(Locked)
Modifying existing functionality3m 17s
-
(Locked)
To mock or not to mock?3m 58s
-
(Locked)
Challenge: Given criteria, write unit tests3m 14s
-
(Locked)
Solution: Given criteria, write unit tests10m 29s
-
-
-
-
-
-
-