Writing an Integration Test
In this lesson, you’ll learn how to write an integration test for an Ember application.
Creating a test component
Components in Ember are tested via integration, or rendering, tests. Let’s type the following command:
ember g component-test star-rating
Ember-CLI has generated the following test stub for us:
Press + to interact
// tests/integration/components/star-rating-test.jsimport { module, test } from 'qunit';import { setupRenderingTest } from 'ember-qunit';import { render } from '@ember/test-helpers';import { hbs } from 'ember-cli-htmlbars';module('Integration | Component | star-rating', function(hooks) {setupRenderingTest(hooks);test('it renders', async function(assert) {// Set any properties with this.set('myProperty', 'value');// Handle any actions with this.set('myAction', function(val) {... });await render(hbs`<StarRating />`);assert.equal(this.element.textContent.trim(), '');// Template block usage:await render(hbs`<StarRating>template block text</StarRating>`);assert.equal(this.element.textContent.trim(), 'template blocktext');});});
Difference between acceptance and integration test stubs
This looks really similar to the acceptance test stub. The first difference is that setupRenderingTest
is imported instead of setupApplicationTest
as a way to prepare the context for the appropriate test. The second ...
Access this course and 1400+ top-rated courses and projects.