Slide 1

Slide 1 text

Testing: The Next Frontier?

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Who the heck is this guy? ● Ember Core Team ● Twitch ● General Open Source Addict twitter: rwjblue github: rwjblue

Slide 4

Slide 4 text

Thank You!!

Slide 5

Slide 5 text

What are we talking about?

Slide 6

Slide 6 text

State of Testing Today ● Acceptance ● Integration ● Unit

Slide 7

Slide 7 text

Acceptance moduleForAcceptance('Acceptance | login'); test('visiting /login', function(assert) { visit('/login'); andThen(function() { assert.equal(currentURL(), '/login'); }); });

Slide 8

Slide 8 text

Integration moduleForComponent('pretty-color', { integration: true }); test('button click', function(assert) { this.render(hbs`{{magic-title}}`); this.$('button').click(); assert.equal(this.$().text(), 'This is Magic'); });

Slide 9

Slide 9 text

Unit moduleFor('route:application'); test('perform the right query', function(assert) { let route = this.subject(); let result = route._queryString(); assert.equal(result, '?awesome=sauce'); });

Slide 10

Slide 10 text

Great, :shipit:

Slide 11

Slide 11 text

The End

Slide 12

Slide 12 text

Seriously?

Slide 13

Slide 13 text

● Built for a globals world. ● “magic” `andThen` ● No ability to stub/mock services. Acceptance Test Issues

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

● Completely ignorant about async ● Manual triggering of user interaction ● Much less “tailored” API Unit/Integration Test Issues

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Now what?

Slide 18

Slide 18 text

emberjs/rfcs#119

Slide 19

Slide 19 text

● Use `async` / `await` ● Consistent interface ● Extendability ● Backwards Compatibility Grand Testing Unification

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Acceptance moduleForAcceptance('Can see things'); test('clicking redirects', async function(assert) { await visit('/things'); let list = find('.thing-item'); assert.equal(list.length, 5); await click('.thing-item[data-id=1]'); assert.equal(this.currentRouteName, 'other- thing'); });

Slide 24

Slide 24 text

Integration moduleForIntegration('post-display'); test('expand when clicked', async function(assert) { await render(hbs`{{post-display}}`); await click('.post-item'); assert.equal( this.find('.post-created-at').textContent, '2016-01-05' ); });

Slide 25

Slide 25 text

● Overriding a service ● Registering custom test helpers ● Registering custom waiters ● Accessing service instances General Testing Concerns

Slide 26

Slide 26 text

● Hooks for work before/after tests. ● Accessing general test information General Testing Concerns

Slide 27

Slide 27 text

Overriding a Service import Mock from 'somewhere/else'; moduleForAcceptance('something', { beforeEach() { this.owner.register('service:stripe', Mock); } });

Slide 28

Slide 28 text

Registering Custom Helpers import selectCategory from '../helpers/select-category'; import loginAsAdmin from '../helpers/login-as-admin'; moduleForAcceptance('Can see things', { beforeEach() { this.registerHelpers({ loginAsAdmin, selectCategory }); } });

Slide 29

Slide 29 text

Custom Helpers // tests/helpers/login-as-admin'; import { testHelper } from 'ember-qunit'; export default testHelper(async function() { await this.click('.login-now'); await this.fillIn('.username', 'rwjblue'); await this.fillIn('.password', 'moar beerz plz'); await this.click('.submit'); });

Slide 30

Slide 30 text

Custom Helpers import selectCategory from '../helpers/select-category'; import loginAsAdmin from '../helpers/login-as-admin'; moduleForAcceptance('Can see things', { beforeEach() { this.registerHelpers({ loginAsAdmin, selectCategory }); } });

Slide 31

Slide 31 text

Custom Waiters import { testWaiter } from 'ember-test-helpers'; import { hasPendingTransactions } from 'app- name/services/transactions'; export default testWaiter(function() { return hasPendingTransactions(); });

Slide 32

Slide 32 text

Custom Waiters import transactionWaiter from '../waiters/pending-transactions'; test('stuff happens', async function(assert) { // Normally done in setup, but slides.... this.registerWaiter(transactionWaiter); await click('.foo'); // all pending transactions are completed here... });

Slide 33

Slide 33 text

Accessing Services test('foo', function(assert) { this.store = this.owner.lookup('service:store'); this.store.push(....); });

Slide 34

Slide 34 text

General Hooks // */tests/configuration.js import { TestConfig } from 'ember-test-helpers'; export default class extends TestConfig { beforeSuite() {} beforeEach(testType, testContext) {} afterEach(testType, testContext) {} }

Slide 35

Slide 35 text

General Hooks // liquid-fire's addon-test-support/configuration.js import { TestConfig } from 'ember-test-helpers'; import runningTransitionWaiter from './waiters/running-transition'; import randoHelper from './helpers/rando'; export default class extends TestConfig { beforeEach() { this.registerWaiter(runningTransitionWaiter); this.registerHelper('randoHelper', randoHelper); } }

Slide 36

Slide 36 text

General Hooks // mirage's addon-test-support/configuration.js import { TestConfig } from 'ember-test-helpers'; import setup from 'ember-cli-mirage/setup-server'; export default class extends TestConfiguration { beforeEach() { this.server = setup(this.owner); } }

Slide 37

Slide 37 text

Test Information import { testHelper } from 'ember-qunit'; export default testHelper(function() { if (this.testInfo.type === 'acceptance') { // acceptance test stuff here } else { // integration/unit test stuff here } });

Slide 38

Slide 38 text

The End