Skip to content

Commit 0121223

Browse files
committed
upgrade to new qunit test structure
1 parent 577c62c commit 0121223

4 files changed

Lines changed: 103 additions & 95 deletions

File tree

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { test } from 'qunit';
2-
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
1+
import { module, test } from 'qunit';
2+
import { visit, currentURL } from '@ember/test-helpers';
3+
import { setupApplicationTest } from 'ember-qunit';
34

4-
moduleForAcceptance('browser acceptance test | shoebox retrieve');
5+
module('browser acceptance test | shoebox retrieve', function(hooks) {
6+
setupApplicationTest(hooks);
57

6-
test('it can retrieve items from the shoebox', function(assert) {
7-
visit('/');
8+
test('it can retrieve items from the shoebox', async function(assert) {
9+
await visit('/');
810

9-
andThen(function() {
1011
assert.equal(currentURL(), '/');
11-
assert.equal(find('.shoebox').text().replace(/\s+/g, ' ').trim(), 'bar zap', 'the data was retreived from the shoebox');
12+
assert.equal(this.element.querySelector('.shoebox').textContent.replace(/\s+/g, ' ').trim(), 'bar zap', 'the data was retreived from the shoebox');
1213
});
13-
});
14+
});

tests/unit/locations/none-test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { moduleFor, test } from 'ember-qunit';
1+
import { module, test } from 'qunit';
2+
import { setupTest } from 'ember-qunit';
23

3-
moduleFor('location:none', 'Unit | Location | none in the browser', {
4-
// Specify the other units that are required for this test.
5-
needs: ['service:fastboot']
6-
});
4+
module('Unit | Location | none in the browser', function(hooks) {
5+
setupTest(hooks);
76

8-
test('setURL ', function (assert) {
9-
let location = this.subject();
10-
location.setURL('foo');
11-
assert.equal(location.get('path'), 'foo', 'it should execute and not call fastboot code');
12-
});
7+
test('setURL ', function (assert) {
8+
let location = this.owner.lookup('location:none');
9+
location.setURL('foo');
10+
assert.equal(location.get('path'), 'foo', 'it should execute and not call fastboot code');
11+
});
12+
});
Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1-
import { moduleFor, test } from 'ember-qunit';
1+
import { module, test } from 'qunit';
2+
import { setupTest } from 'ember-qunit';
23

3-
moduleFor('service:fastboot', 'Unit | Service | fastboot in the browser', {});
4+
module('Unit | Service | fastboot in the browser', function(hooks) {
5+
setupTest(hooks);
46

5-
test('isFastBoot', function(assert) {
6-
let service = this.subject();
7-
assert.equal(service.isFastBoot, false, `it should be false`);
8-
assert.equal(service.get('isFastBoot'), false, `it should be false`);
9-
});
7+
test('isFastBoot', function(assert) {
8+
let service = this.owner.lookup('service:fastboot');
9+
assert.equal(service.isFastBoot, false, `it should be false`);
10+
assert.equal(service.get('isFastBoot'), false, `it should be false`);
11+
});
1012

11-
test('request', function(assert) {
12-
let service = this.subject();
13-
assert.equal(service.get('request'), null, `it should be null`);
14-
});
13+
test('request', function(assert) {
14+
let service = this.owner.lookup('service:fastboot');
15+
assert.equal(service.get('request'), null, `it should be null`);
16+
});
1517

16-
test('response', function(assert) {
17-
let service = this.subject();
18-
assert.equal(service.get('response'), null, `it should be null`);
19-
});
18+
test('response', function(assert) {
19+
let service = this.owner.lookup('service:fastboot');
20+
assert.equal(service.get('response'), null, `it should be null`);
21+
});
2022

21-
test('metadata', function(assert) {
22-
let service = this.subject();
23-
assert.equal(service.get('metadata'), null, `it should be null`);
24-
});
23+
test('metadata', function(assert) {
24+
let service = this.owner.lookup('service:fastboot');
25+
assert.equal(service.get('metadata'), null, `it should be null`);
26+
});
27+
});
Lines changed: 62 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,92 @@
1-
import { moduleFor, test } from 'ember-qunit';
1+
import { module, test } from 'qunit';
2+
import { setupTest } from 'ember-qunit';
23
import sinon from 'sinon';
34

45
let sandbox;
56

6-
moduleFor('service:fastboot', 'Unit | Service | fastboot | shoebox', {
7-
beforeEach() {
7+
module('Unit | Service | fastboot | shoebox', function(hooks) {
8+
setupTest(hooks);
9+
10+
hooks.beforeEach(function() {
811
sandbox = sinon.sandbox.create();
9-
},
10-
afterEach() {
12+
});
13+
14+
hooks.afterEach(function() {
1115
sandbox.restore();
12-
}
13-
});
16+
});
1417

15-
test('retrieve returns value if isFastBoot false and key is cached', function(assert) {
16-
let service = this.subject();
18+
test('retrieve returns value if isFastBoot false and key is cached', function(assert) {
19+
let service = this.owner.lookup('service:fastboot');
1720

18-
service.set('shoebox.foo', 'bar');
21+
service.set('shoebox.foo', 'bar');
1922

20-
assert.strictEqual(service.get('shoebox').retrieve('foo'), 'bar');
21-
});
23+
assert.strictEqual(service.get('shoebox').retrieve('foo'), 'bar');
24+
});
2225

23-
test('retrieve returns undefined if isFastBoot false and shoebox is missing', function(assert) {
24-
let service = this.subject();
26+
test('retrieve returns undefined if isFastBoot false and shoebox is missing', function(assert) {
27+
let service = this.owner.lookup('service:fastboot');
2528

26-
let stub = sandbox.stub(document, 'querySelector').withArgs('#shoebox-foo');
29+
let stub = sandbox.stub(document, 'querySelector').withArgs('#shoebox-foo');
2730

28-
assert.strictEqual(service.get('shoebox').retrieve('foo'), undefined);
31+
assert.strictEqual(service.get('shoebox').retrieve('foo'), undefined);
2932

30-
sinon.assert.calledOnce(stub);
31-
});
33+
sinon.assert.calledOnce(stub);
34+
});
3235

33-
test('retrieve returns undefined if isFastBoot false and textContent is missing', function(assert) {
34-
let service = this.subject();
36+
test('retrieve returns undefined if isFastBoot false and textContent is missing', function(assert) {
37+
let service = this.owner.lookup('service:fastboot');
3538

36-
let stub = sandbox.stub(document, 'querySelector').withArgs('#shoebox-foo').returns({});
39+
let stub = sandbox.stub(document, 'querySelector').withArgs('#shoebox-foo').returns({});
3740

38-
assert.strictEqual(service.get('shoebox').retrieve('foo'), undefined);
41+
assert.strictEqual(service.get('shoebox').retrieve('foo'), undefined);
3942

40-
sinon.assert.calledOnce(stub);
41-
});
43+
sinon.assert.calledOnce(stub);
44+
});
4245

43-
test('retrieve returns value if isFastBoot false and textContent is present', function(assert) {
44-
let service = this.subject();
46+
test('retrieve returns value if isFastBoot false and textContent is present', function(assert) {
47+
let service = this.owner.lookup('service:fastboot');
4548

46-
let stub = sandbox.stub(document, 'querySelector').withArgs('#shoebox-foo').returns({
47-
textContent: '{"foo":"bar"}'
48-
});
49+
let stub = sandbox.stub(document, 'querySelector').withArgs('#shoebox-foo').returns({
50+
textContent: '{"foo":"bar"}'
51+
});
52+
53+
assert.deepEqual(service.get('shoebox').retrieve('foo'), {
54+
foo: 'bar'
55+
});
4956

50-
assert.deepEqual(service.get('shoebox').retrieve('foo'), {
51-
foo: 'bar'
57+
sinon.assert.calledOnce(stub);
5258
});
5359

54-
sinon.assert.calledOnce(stub);
55-
});
60+
test('retrieve returns undefined if isFastBoot true and shoebox is missing', function(assert) {
61+
let service = this.owner.factoryFor('service:fastboot').create({
62+
isFastBoot: true,
63+
_fastbootInfo: {}
64+
});
5665

57-
test('retrieve returns undefined if isFastBoot true and shoebox is missing', function(assert) {
58-
let service = this.subject({
59-
isFastBoot: true,
60-
_fastbootInfo: {}
66+
assert.strictEqual(service.get('shoebox').retrieve('foo'), undefined);
6167
});
6268

63-
assert.strictEqual(service.get('shoebox').retrieve('foo'), undefined);
64-
});
69+
test('retrieve returns undefined if isFastBoot true and key is missing', function(assert) {
70+
let service = this.owner.factoryFor('service:fastboot').create({
71+
isFastBoot: true,
72+
_fastbootInfo: {
73+
shoebox: {}
74+
}
75+
});
6576

66-
test('retrieve returns undefined if isFastBoot true and key is missing', function(assert) {
67-
let service = this.subject({
68-
isFastBoot: true,
69-
_fastbootInfo: {
70-
shoebox: {}
71-
}
77+
assert.strictEqual(service.get('shoebox').retrieve('foo'), undefined);
7278
});
7379

74-
assert.strictEqual(service.get('shoebox').retrieve('foo'), undefined);
75-
});
76-
77-
test('retrieve returns value if isFastBoot true and key is present', function(assert) {
78-
let service = this.subject({
79-
isFastBoot: true,
80-
_fastbootInfo: {
81-
shoebox: {
82-
foo: 'bar'
80+
test('retrieve returns value if isFastBoot true and key is present', function(assert) {
81+
let service = this.owner.factoryFor('service:fastboot').create({
82+
isFastBoot: true,
83+
_fastbootInfo: {
84+
shoebox: {
85+
foo: 'bar'
86+
}
8387
}
84-
}
85-
});
88+
});
8689

87-
assert.strictEqual(service.get('shoebox').retrieve('foo'), 'bar');
88-
});
90+
assert.strictEqual(service.get('shoebox').retrieve('foo'), 'bar');
91+
});
92+
});

0 commit comments

Comments
 (0)