Writing Unit Tests for Angular Components
Browser-based acceptance tests are slow and brittle. Even though we’ve eschewed starting an actual browser for each test by using PhantomJS, we still have to start our server and have it serve pages to the headless browser. Further, our tests rely on DOM elements and CSS classes to locate content used to verify behavior. We may need (or want) to make changes to the view that don’t break functionality but break our tests.
Although we don’t want to abandon acceptance tests—after all, they are the only tests we have that exercise the system end to end—we need a way to test isolated bits of functionality (commonly called unit tests). In Rails, we have model tests and controller tests that allow us to do ...
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.
Read now
Unlock full access