How to use Expect assertion library in CodePen

Vlad Bezden

I really like Michael Jackson’s Expect assertion library. It’s very simple and it’s very easy to use. Expert from Expect GitHub web site:

expect lets you write better assertions.

When you use expect, you write assertions similarly to how you would say them, e.g. “I expect this value to be equal to 3” or “I expect this array to contain 3”. When you write assertions in this way, you don’t need to remember the order of actual and expected arguments to functions like assert.equal, which helps you write better tests.

I found it is very useful to use Expect library in CodePen, this way you don’t have to output your code to console, but just run your test and see if it passed or not.

Here is a Pen that uses Expect:

In order to use Expect library you need to add it to your Pen.

After you created once you can mark this Pen to use as Template, this way you don’t have to add this library every time you would like to create a new Pen with Expect library. I already created Expect template Pen so feel free to use it in your code. All you have to do is to add reference to my Pen

Happy Coding :)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade