Check out a free preview of the full JavaScript Testing Practices and Principles course

The "Writing a Basic Unit Test Exercise" Lesson is part of the full, JavaScript Testing Practices and Principles course featured in this preview video. Here's what you'd learn in this lesson:

Kent introduces the userToJson exercise, which is a practical look at testing a JavaScript utility function.

Preview
Close

Transcript from the "Writing a Basic Unit Test Exercise" Lesson

[00:00:00]
>> Kent C. Dodds: All right, so I'm gonna set you off on this. So again, this is taking a user object, and I've got an example of a user object. You can just un-comment that and take that if you want to. But this is the user object and by the end of your test it should only have the first two properties here, the ID and username.

[00:00:23]
The rest of these are considered safe properties and they should be omitted. So you’ll call the user object with this user, it’ll give you back a new user. And you’ll verify that that new user doesn’t have the properties it's not supposed to have.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now