forked from emberjs/ember-qunit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadapter.js
40 lines (32 loc) · 1.01 KB
/
adapter.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
import Ember from 'ember';
import * as QUnit from 'qunit';
export function nonTestDoneCallback() {}
let Adapter = Ember.Test.Adapter.extend({
init() {
this.doneCallbacks = [];
this.qunit = this.qunit || QUnit;
},
asyncStart() {
let currentTest = this.qunit.config.current;
let done =
currentTest && currentTest.assert
? currentTest.assert.async()
: nonTestDoneCallback;
this.doneCallbacks.push({ test: currentTest, done });
},
asyncEnd() {
let currentTest = this.qunit.config.current;
if (this.doneCallbacks.length === 0) {
throw new Error(
'Adapter asyncEnd called when no async was expected. Please create an issue in ember-qunit.'
);
}
let { test, done } = this.doneCallbacks.pop();
// In future, we should explore fixing this at a different level, specifically
// addressing the pairing of asyncStart/asyncEnd behavior in a more consistent way.
if (test === currentTest) {
done();
}
},
});
export default Adapter;