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 basic functions - JavaScript Tutorial
From the course: JavaScript: Test-Driven Development (ES6)
Testing basic functions
- [Instructor] Okay and that's all the set up we need for now. So now that we've got everything set up, let's talk about what we're going to be coding here. To get a better sense of how the tdd process works, we're going to code a simple example function. And this function is going to take a string as an argument and return an object that contains a count of all the letters in that string. So for example if we pass at the string cat, it'll return an object that looks like this, c:1, a:1, t:1 because the string cat has one c, one a and one t in it. And likewise if we pass at the string better, B-E-T-T-E-R, it'll return an object that looks like this, b:1, e:2 'cause there's two e's, t:2 'cause there's two t's, and r:1, and so on. Now as a matter of fact these two examples I just gave you would make great test cases to test our function with. So let's see how to do that. Let's open up our letter-count.test file and write…
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
-
-
-
-
-
-
-