forked from emberjs/ember-qunit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module-for-component.js
59 lines (47 loc) · 1.69 KB
/
module-for-component.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
import testResolver from './test-resolver';
import moduleFor from './module-for';
import Ember from 'ember';
export default function moduleForComponent(name, description, callbacks) {
var resolver = testResolver.get();
moduleFor('component:' + name, description, callbacks, function(container, context, defaultSubject) {
var layoutName = 'template:components/' + name;
var layout = resolver.resolve(layoutName);
if (layout) {
container.register(layoutName, layout);
container.injection('component:' + name, 'layout', layoutName);
}
context.dispatcher = Ember.EventDispatcher.create();
context.dispatcher.setup({}, '#ember-testing');
context.__setup_properties__.render = function() {
var containerView = Ember.ContainerView.create({container: container});
var view = Ember.run(function(){
var subject = context.subject();
containerView.pushObject(subject);
containerView.appendTo('#ember-testing');
return subject;
});
var oldTeardown = this.teardown;
this.teardown = function() {
Ember.run(function() {
Ember.tryInvoke(containerView, 'destroy');
});
if (oldTeardown) {
return oldTeardown.apply(this, arguments);
}
};
return view.$();
};
context.__setup_properties__.append = function(){
Ember.deprecate('this.append() is deprecated. Please use this.render() instead.');
return this.render();
};
context.$ = function(){
var $view = this.render(), subject = this.subject();
if(arguments.length){
return subject.$.apply(subject, arguments);
}else{
return $view;
}
};
});
}