Skip to Main Content
Eloquent JavaScript
book

Eloquent JavaScript

by Marijn Haverbeke
January 2011
Intermediate to advanced content levelIntermediate to advanced
224 pages
5h 43m
English
No Starch Press
Content preview from Eloquent JavaScript

Automated Testing

Because JavaScript programs aren’t checked very thoroughly before execution and because manually testing every if branch in a big program can take a lot of time, mistakes can sit lurking in the depths of programs, even when they appear to work fine.

For some pieces of code—those that work without too much interaction with their environment—it is very straightforward to write automated tests. These are programs that test programs. To test the between function we saw in this chapter, you could, for example, write something like this:

function testBetween() { function assert(name, x) { if (!x) throw "Assertion failed: " + name; } assert("identical delimiters", between("a |b| c", "|", "|") == "b"); assert("whole string", between("[[n]]", ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Eloquent JavaScript, 3rd Edition

Eloquent JavaScript, 3rd Edition

Marijn Haverbeke
Learn JavaScript

Learn JavaScript

Shaun Wassell

Publisher Resources

ISBN: 9781593272821Errata