-
-
Notifications
You must be signed in to change notification settings - Fork 157
/
test-utilities-test.js
169 lines (132 loc) · 5.18 KB
/
test-utilities-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import Ember from 'ember';
import { timeout } from 'ember-concurrency';
import { test } from 'ember-concurrency/qunit';
import { module } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
const { $ } = Ember;
module('ember-concurrency testing utilities');
test('sync tests work', function * (assert) {
assert.expect(1);
assert.ok(true);
});
test('async tests work', function * (assert) {
assert.expect(1);
yield timeout(100);
assert.ok(true);
});
test('tests run outside of run loops', function * (assert) {
assert.expect(2);
assert.ok(!Ember.run.currentRunLoop);
yield timeout(100);
assert.ok(!Ember.run.currentRunLoop);
});
moduleForAcceptance('ember-concurrency testing utilities (acceptance)');
test('find() waits for element to exist', function * (assert) {
assert.expect(2);
this.visit('/testing-ergo/foo');
let sel = `.eventual-button:contains('Eventual Button')`;
assert.equal($(sel).length, 0);
let $loadedSel = yield this.find(sel);
assert.equal($loadedSel.length, 1);
});
test('find() with count 0 waits for element to not exist', function * (assert) {
assert.expect(1);
this.visit('/testing-ergo/foo');
yield this.find(`.disappearing-content`);
let $sel = yield this.find(`.disappearing-content`, { count: 0 });
assert.equal($sel.length, 0);
});
test('click() waits for element to exist', function * (assert) {
assert.expect(0);
this.visit('/testing-ergo/foo');
yield this.click(`.eventual-button`);
yield this.find(`.value:contains('value=123')`);
});
test('find() fails eagerly if waiters settle', function * (assert) {
assert.expect(1);
this.visit('/testing-ergo/foo-settimeout');
try {
yield this.find(`.eventual-button`);
} catch(e) {
assert.equal(e.message, "Tried to find 1 occurrence(s) of \".eventual-button\" before test waiters settled, instead found 0");
}
});
test('find() can wait beyond settlement using timeout option', function * (assert) {
assert.expect(2);
this.visit('/testing-ergo/foo-settimeout');
try {
yield this.find(`.nonexistent-button`, { timeout: 100 });
} catch(e) {
assert.equal(e.message, "Tried to find 1 occurrence(s) of \".nonexistent-button\" within 100ms, instead found 0");
}
let $el = yield this.find(`.eventual-button`, { timeout: 1000 });
assert.equal($el.length, 1);
});
test('it is easy to test loading routes by yielding selectors rather than awaiting "settledness"', function * (assert) {
assert.expect(2);
this.visit('/testing-ergo/slow');
let $loadingBanner = yield this.find('.loading-message');
assert.equal($loadingBanner.text(), "I am a loading route.");
let $slowBanner = yield this.find('.slow-banner');
assert.equal($slowBanner.text(), "Welcome to slow route.");
});
test('it is easy to test timer loops', function * (assert) {
assert.expect(0);
this.visit('/testing-ergo/timer-loop');
yield this.find(`.timer-loop-message:contains('foo=5')`);
});
moduleForAcceptance('ember-concurrency testing utilities (async await acceptance)');
test('find() waits for element to exist', async function (assert) {
assert.expect(2);
this.visit('/testing-ergo/foo');
let sel = `.eventual-button:contains('Eventual Button')`;
assert.equal($(sel).length, 0);
let $loadedSel = await this.find(sel);
assert.equal($loadedSel.length, 1);
});
test('find() with count 0 waits for element to not exist', async function (assert) {
assert.expect(1);
this.visit('/testing-ergo/foo');
await this.find(`.disappearing-content`);
let $sel = await this.find(`.disappearing-content`, { count: 0 });
assert.equal($sel.length, 0);
});
test('click() waits for element to exist', async function(assert) {
assert.expect(0);
this.visit('/testing-ergo/foo');
await this.click(`.eventual-button`);
await this.find(`.value:contains('value=123')`);
});
test('find() fails eagerly if waiters settle', async function(assert) {
assert.expect(1);
this.visit('/testing-ergo/foo-settimeout');
try {
await this.find(`.eventual-button`);
} catch(e) {
assert.equal(e.message, "Tried to find 1 occurrence(s) of \".eventual-button\" before test waiters settled, instead found 0");
}
});
test('find() can wait beyond settlement using timeout option', async function(assert) {
assert.expect(2);
this.visit('/testing-ergo/foo-settimeout');
try {
await this.find(`.nonexistent-button`, { timeout: 100 });
} catch(e) {
assert.equal(e.message, "Tried to find 1 occurrence(s) of \".nonexistent-button\" within 100ms, instead found 0");
}
let $el = await this.find(`.eventual-button`, { timeout: 1000 });
assert.equal($el.length, 1);
});
test('it is easy to test loading routes by yielding selectors rather than awaiting "settledness"', async function(assert) {
assert.expect(2);
this.visit('/testing-ergo/slow');
let $loadingBanner = await this.find('.loading-message');
assert.equal($loadingBanner.text(), "I am a loading route.");
let $slowBanner = await this.find('.slow-banner');
assert.equal($slowBanner.text(), "Welcome to slow route.");
});
test('it is easy to test timer loops', async function(assert) {
assert.expect(0);
this.visit('/testing-ergo/timer-loop');
await this.find(`.timer-loop-message:contains('foo=5')`);
});