Skip to content

Commit

Permalink
Ensure callbacks are called in the test module's context.
Browse files Browse the repository at this point in the history
Provides access to any of a module's properties (e.g. `container`,
`callbacks`, etc.) from within a callback.
  • Loading branch information
dgeb committed Feb 10, 2015
1 parent 422fc47 commit feb3824
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/ember-test-helpers/test-module-for-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default TestModule.extend({

this.callbacks.append = function() {
Ember.deprecate('this.append() is deprecated. Please use this.render() instead.');
return this.render();
return this.callbacks.render();
};

context.$ = function() {
Expand Down
3 changes: 2 additions & 1 deletion lib/ember-test-helpers/test-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ export default Klass.extend({
context[key] = function(options) {
if (_this.cache[key]) { return _this.cache[key]; }

var result = callbacks[key](options, factory());
var result = callbacks[key].call(_this, options, factory());

_this.cache[key] = result;

return result;
Expand Down
14 changes: 14 additions & 0 deletions tests/test-module-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,17 @@ test("can lookup factory registered in setup", function() {

equal(service.get('purpose'), 'blabering');
});

moduleFor('component:x-foo', 'component:x-foo -- callback context', {
beforeSetup: function() {
setupRegistry();
},

getSubjectName: function() {
return this.subjectName;
}
});

test("callbacks are called in the context of the module", function() {
equal(this.getSubjectName(), 'component:x-foo');
});

0 comments on commit feb3824

Please sign in to comment.