forked from emberjs/ember.js
/
adapters_test.js
94 lines (74 loc) · 2.18 KB
/
adapters_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
import { run } from 'ember-metal';
import Test from '../test';
import Adapter from '../adapters/adapter';
import QUnitAdapter from '../adapters/qunit';
import { Application as EmberApplication } from 'ember-application';
var App, originalAdapter, originalQUnit, originalWindowOnerror;
QUnit.module('ember-testing Adapters', {
setup() {
originalAdapter = Test.adapter;
originalQUnit = window.QUnit;
originalWindowOnerror = window.onerror;
},
teardown() {
if (App) {
run(App, App.destroy);
App.removeTestHelpers();
App = null;
}
Test.adapter = originalAdapter;
window.QUnit = originalQUnit;
window.onerror = originalWindowOnerror;
}
});
QUnit.test('Setting a test adapter manually', function() {
expect(1);
var CustomAdapter;
CustomAdapter = Adapter.extend({
asyncStart() {
ok(true, 'Correct adapter was used');
}
});
run(function() {
App = EmberApplication.create();
Test.adapter = CustomAdapter.create();
App.setupForTesting();
});
Test.adapter.asyncStart();
});
QUnit.test('QUnitAdapter is used by default (if QUnit is available)', function() {
expect(1);
Test.adapter = null;
run(function() {
App = EmberApplication.create();
App.setupForTesting();
});
ok(Test.adapter instanceof QUnitAdapter);
});
QUnit.test('Adapter is used by default (if QUnit is not available)', function() {
expect(2);
delete window.QUnit;
Test.adapter = null;
run(function() {
App = EmberApplication.create();
App.setupForTesting();
});
ok(Test.adapter instanceof Adapter);
ok(!(Test.adapter instanceof QUnitAdapter));
});
QUnit.test('With Ember.Test.adapter set, errors in synchronous Ember.run are bubbled out', function (assert) {
let thrown = new Error('Boom!');
let caughtInAdapter, caughtInCatch;
Test.adapter = QUnitAdapter.create({
exception(error) {
caughtInAdapter = error;
}
});
try {
run(() => { throw thrown; });
} catch(e) {
caughtInCatch = e;
}
assert.equal(caughtInAdapter, undefined, 'test adapter should never receive synchronous errors');
assert.equal(caughtInCatch, thrown, 'a "normal" try/catch should catch errors in sync run');
});