forked from emberjs/ember-qunit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-test-test.js
65 lines (52 loc) · 1.65 KB
/
setup-test-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
import { module, test } from 'qunit';
import Service, { inject as injectService } from '@ember/service';
import Component from '@ember/component';
import { setupTest } from 'ember-qunit';
import { setResolverRegistry } from '../helpers/resolver';
module('setupTest tests', function (hooks) {
hooks.beforeEach(function () {
setResolverRegistry({});
});
setupTest(hooks);
test('can be used for unit style testing', function (assert) {
this.owner.register(
'service:foo',
Service.extend({
someMethod() {
return 'hello thar!';
},
})
);
let subject = this.owner.lookup('service:foo');
assert.equal(subject.someMethod(), 'hello thar!');
});
test('can access a shared service instance', function (assert) {
this.owner.register('service:bar', Service.extend());
this.owner.register(
'service:foo',
Service.extend({
bar: injectService(),
someMethod() {
this.set('bar.someProp', 'derp');
},
})
);
let subject = this.owner.lookup('service:foo');
let bar = this.owner.lookup('service:bar');
assert.notOk(bar.get('someProp'), 'precond - initially undefined');
subject.someMethod();
assert.equal(bar.get('someProp'), 'derp', 'property updated');
});
test('can create a component instance for direct testing without a template', function (assert) {
this.owner.register(
'component:foo-bar',
Component.extend({
someMethod() {
return 'hello thar!';
},
})
);
let subject = this.owner.lookup('component:foo-bar');
assert.equal(subject.someMethod(), 'hello thar!');
});
});