Testing
A great testing story is a critical part of any serious tech stack, and the Ember community has put a lot of time into making this a great strength of the framework. We'll cover examples and best practices in areas of :
- Unit testing
- Component integration testing
- Acceptance testing
- Mocking data
- Writing sustainable tests
-
TestingA Single-Page App Testing Primer
We'll go over the unique challenges and concerns that pertain to writing, debugging and maintaining tests for a Single-Page App.
-
TestingUnit Testing
Unit tests are great for testing algorithmic complexity. In particular, they're the go-to flavor of test for models, handlebars helpers, utility functions, and other common things like computed property macros. We'll cover concepts like:
- Mocking data
- Testing setup/teardown hooks
- The Qunit assertion library
-
TestingExercise: Writing Unit Tests
We'll write some unit tests for the handlebars helpers we wrote earlier, and build a computed property marco, complete with unit tests!
-
TestingComponent Testing
Thanks to the ability to write small pieces of inline handlebars template to set up test scenarios, component integration testing is easier than ever before! Integration tests are designed to establish that a contract between two things works as expected, so we'll examine different ways of testing the component's contract with the outside world, including:
- Passing data into the component
- Receiving calls to actions bound to the component
- Injecting services into the component, for just for testing
-
TestingExercise: Writing Component Tests
We'll write some component tests for our existing components, exploring issues like:
- Setting up a realistic test scenario
- Examining changes to bound data
- Stubbing services
- Verifying that actions have been fired
-
TestingAcceptance Tests
Acceptance tests are great for ensuring that critical workflows work as expected. They're much slower than unit or component integration tests, since they are run against your app as a whole, but this is a great way to ensure that the whole thing works together as expected. We'll explore topics relevant to acceptance testing like:
- Async test helpers
- Maintainable CSS selectors for tests
- Mocking data with Pretender
-
TestingExercise: Writing Acceptance Tests
We'll incrementally write an acceptance test to test one of the critical workflows in our app, using Qunit 3's development mode, and Pretender to mock AJAX JSON responses without using our usual REST API.