O'Reilly logo

AngularJS Directives by Alex Vanston

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Negative testing

Generally, when we first start testing, we think of all the things that need to happen and then test for them, which is an awesome start. What we often forget however, is that we need to decide, and test for, what happens when something goes wrong, or when that 'it-could-never-happen' case happens. Consider our player list and what would happen if we received a player object without a team. There are plenty of reasons why this might happen—they're undrafted, a database corruption, or your data-entry intern missed their coffee that morning—but, whatever the reason, we need to make sure our directive can handle it cleanly. Right now, if we were to pass that in, we'd end up with the following rather unprofessional output:

... <p class="player">John ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required