Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce resolver option to test module #174

Merged
merged 2 commits into from
Aug 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/ember-test-helpers/test-module-for-component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import TestModule from './test-module';
import Ember from 'ember';
import { getResolver } from './test-resolver';
import hasEmberVersion from './has-ember-version';
import { preGlimmerSetupIntegrationForComponent } from './-legacy-overrides';

Expand Down Expand Up @@ -84,7 +83,7 @@ export default TestModule.extend({

setupComponentUnitTest: function() {
var _this = this;
var resolver = getResolver();
var resolver = this.resolver;
var context = this.context;

var layoutName = 'template:components/' + this.componentName;
Expand Down
7 changes: 6 additions & 1 deletion lib/ember-test-helpers/test-module-for-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ if (hasEmberVersion(2,0)) {
}

export default AbstractTestModule.extend({
init() {
this._super(...arguments);
this.resolver = this.callbacks.resolver || getResolver();
},

initSetupSteps() {
this.setupSteps = [];
this.contextualizedSetupSteps = [];
Expand Down Expand Up @@ -66,7 +71,7 @@ export default AbstractTestModule.extend({
},

setupContainer() {
var resolver = getResolver();
var resolver = this.resolver;
var items = buildRegistry(resolver);

this.container = items.container;
Expand Down
5 changes: 3 additions & 2 deletions lib/ember-test-helpers/test-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default AbstractTestModule.extend({
this.description = description || subjectName;
this.name = description || subjectName;
this.callbacks = callbacks || {};
this.resolver = this.callbacks.resolver || getResolver();

if (this.callbacks.integration && this.callbacks.needs) {
throw new Error("cannot declare 'integration: true' and 'needs' in the same module");
Expand Down Expand Up @@ -234,7 +235,7 @@ export default AbstractTestModule.extend({
},

_setupContainer: function(isolated) {
var resolver = getResolver();
var resolver = this.resolver;

var items = buildRegistry(!isolated ? resolver : Object.create(resolver, {
resolve: {
Expand All @@ -254,7 +255,7 @@ export default AbstractTestModule.extend({
},

_setupIsolatedContainer: function() {
var resolver = getResolver();
var resolver = this.resolver;
this._setupContainer(true);

var thingToRegisterWith = this.registry || this.container;
Expand Down
18 changes: 17 additions & 1 deletion tests/test-module-for-integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import hasEmberVersion from 'ember-test-helpers/has-ember-version';
import { TestModuleForIntegration } from 'ember-test-helpers';
import test from 'tests/test-support/qunit-test';
import qunitModuleFor from 'tests/test-support/qunit-module-for';
import { setResolverRegistry } from 'tests/test-support/resolver';
import { setResolverRegistry, createCustomResolver } from 'tests/test-support/resolver';

const Service = Ember.Service || Ember.Object;

Expand Down Expand Up @@ -274,3 +274,19 @@ test('still in DOM in willDestroyElement', function() {

ok(willDestroyCalled, 'can add assertions after willDestroyElement is called');
});

moduleForIntegration('TestModuleForIntegration | custom resolver', {
resolver: createCustomResolver({
'component:y-foo': Ember.Component.extend({
name: 'Y u no foo?!'
}),
'template:components/y-foo': Ember.Handlebars.compile(
'<span class="name">{{name}}</span>'
)
})
});

test('can render with a custom resolver', function() {
this.render('{{y-foo}}');
equal(this.$('.name').text(), 'Y u no foo?!', 'rendered properly');
});
14 changes: 13 additions & 1 deletion tests/test-module-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TestModule, getContext } from 'ember-test-helpers';
import hasEmberVersion from 'ember-test-helpers/has-ember-version';
import test from 'tests/test-support/qunit-test';
import qunitModuleFor from 'tests/test-support/qunit-module-for';
import { setResolverRegistry } from 'tests/test-support/resolver';
import { setResolverRegistry, createCustomResolver } from 'tests/test-support/resolver';

function moduleFor(fullName, description, callbacks) {
var module = new TestModule(fullName, description, callbacks);
Expand Down Expand Up @@ -335,3 +335,15 @@ QUnit.module('context can be provided to TestModule', {
test('noop', function() {
contexts.push(this);
});

moduleFor('component:y-foo', 'Custom resolver', {
resolver: createCustomResolver({
'component:y-foo': Ember.Component.extend({
name: 'Y u no foo?!'
})
})
});

test('subject created using custom resolver', function() {
equal(this.subject().name, 'Y u no foo?!');
});
16 changes: 16 additions & 0 deletions tests/test-support/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,19 @@ export default {
return resolver;
}
};

export function createCustomResolver(registry) {
var Resolver = Ember.DefaultResolver.extend({
registry: null,

resolve(fullName) {
return this.registry[fullName];
},

normalize(fullName) {
return Ember.String.dasherize(fullName);
}
});

return Resolver.create({ registry, namespace: {} });
}