ember-test-helpers
Advanced tools
Comparing version 0.5.24 to 0.5.25
@@ -5,3 +5,11 @@ import TestModule from './test-module'; | ||
import hasEmberVersion from './has-ember-version'; | ||
import { preoutletRefactorSetupIntegrationForComponent } from './-legacy-overrides'; | ||
let ACTION_KEY; | ||
if (hasEmberVersion(2,0)) { | ||
ACTION_KEY = 'actions'; | ||
} else { | ||
ACTION_KEY = '_actions'; | ||
} | ||
export default TestModule.extend({ | ||
@@ -126,89 +134,104 @@ isComponentTestModule: true, | ||
setupComponentIntegrationTest: function() { | ||
var module = this; | ||
var context = this.context; | ||
setupComponentIntegrationTest: (function() { | ||
if (!hasEmberVersion(1,11)) { | ||
return preoutletRefactorSetupIntegrationForComponent; | ||
} else { | ||
return function() { | ||
var module = this; | ||
var context = this.context; | ||
this.actionHooks = {}; | ||
this.actionHooks = context[ACTION_KEY] = {}; | ||
context.dispatcher = this.container.lookup('event_dispatcher:main') || Ember.EventDispatcher.create(); | ||
context.dispatcher.setup({}, '#ember-testing'); | ||
context.dispatcher = this.container.lookup('event_dispatcher:main') || Ember.EventDispatcher.create(); | ||
context.dispatcher.setup({}, '#ember-testing'); | ||
context.actions = module.actionHooks; | ||
var OutletView = module.container.lookupFactory('view:-outlet'); | ||
var toplevelView = module.component = OutletView.create(); | ||
toplevelView.setOutletState({ render: { }, outlets: { }}); | ||
(this.registry || this.container).register('component:-test-holder', Ember.Component.extend()); | ||
var element = document.getElementById('ember-testing'); | ||
Ember.run(module.component, 'appendTo', '#ember-testing'); | ||
context.render = function(template) { | ||
// in case `this.render` is called twice, make sure to teardown the first invocation | ||
module.teardownComponent(); | ||
context.render = function(template) { | ||
if (!template) { | ||
throw new Error("in a component integration test you must pass a template to `render()`"); | ||
} | ||
if (Ember.isArray(template)) { | ||
template = template.join(''); | ||
} | ||
if (typeof template === 'string') { | ||
template = Ember.Handlebars.compile(template); | ||
} | ||
if (!template) { | ||
throw new Error("in a component integration test you must pass a template to `render()`"); | ||
} | ||
if (Ember.isArray(template)) { | ||
template = template.join(''); | ||
} | ||
if (typeof template === 'string') { | ||
template = Ember.Handlebars.compile(template); | ||
} | ||
module.component = module.container.lookupFactory('component:-test-holder').create({ | ||
layout: template | ||
}); | ||
Ember.run(function() { | ||
toplevelView.setOutletState({ | ||
render: { | ||
controller: module.context, | ||
template | ||
} | ||
}); | ||
}); | ||
}; | ||
module.component.set('context' ,context); | ||
module.component.set('controller', context); | ||
context.$ = function(selector) { | ||
// emulates Ember internal behavor of `this.$` in a component | ||
// https://github.com/emberjs/ember.js/blob/v2.5.1/packages/ember-views/lib/views/states/has_element.js#L18 | ||
return selector ? Ember.$(selector, element) : Ember.$(element); | ||
}; | ||
Ember.run(function() { | ||
module.component.appendTo('#ember-testing'); | ||
}); | ||
}; | ||
context.set = function(key, value) { | ||
var ret = Ember.run(function() { | ||
return Ember.set(context, key, value); | ||
}); | ||
context.$ = function() { | ||
return module.component.$.apply(module.component, arguments); | ||
}; | ||
if (hasEmberVersion(2,0)) { | ||
return ret; | ||
} | ||
}; | ||
context.set = function(key, value) { | ||
var ret = Ember.run(function() { | ||
return Ember.set(context, key, value); | ||
}); | ||
context.setProperties = function(hash) { | ||
var ret = Ember.run(function() { | ||
return Ember.setProperties(context, hash); | ||
}); | ||
if (hasEmberVersion(2,0)) { | ||
return ret; | ||
} | ||
}; | ||
if (hasEmberVersion(2,0)) { | ||
return ret; | ||
} | ||
}; | ||
context.setProperties = function(hash) { | ||
var ret = Ember.run(function() { | ||
return Ember.setProperties(context, hash); | ||
}); | ||
context.get = function(key) { | ||
return Ember.get(context, key); | ||
}; | ||
if (hasEmberVersion(2,0)) { | ||
return ret; | ||
} | ||
}; | ||
context.getProperties = function() { | ||
var args = Array.prototype.slice.call(arguments); | ||
return Ember.getProperties(context, args); | ||
}; | ||
context.get = function(key) { | ||
return Ember.get(context, key); | ||
}; | ||
context.on = function(actionName, handler) { | ||
module.actionHooks[actionName] = handler; | ||
}; | ||
context.getProperties = function() { | ||
var args = Array.prototype.slice.call(arguments); | ||
return Ember.getProperties(context, args); | ||
}; | ||
context.send = function(actionName) { | ||
var hook = module.actionHooks[actionName]; | ||
if (!hook) { | ||
throw new Error("integration testing template received unexpected action " + actionName); | ||
} | ||
hook.apply(module.context, Array.prototype.slice.call(arguments, 1)); | ||
}; | ||
context.on = function(actionName, handler) { | ||
module.actionHooks[actionName] = handler; | ||
}; | ||
context.clearRender = function() { | ||
Ember.run(function() { | ||
toplevelView.setOutletState({ | ||
render: { | ||
controller: module.context, | ||
randomKey: 'empty' | ||
}, | ||
outlets: {} | ||
}); | ||
}); | ||
}; | ||
}; | ||
} | ||
})(), | ||
context.send = function(actionName) { | ||
var hook = module.actionHooks[actionName]; | ||
if (!hook) { | ||
throw new Error("integration testing template received unexpected action " + actionName); | ||
} | ||
hook.apply(module, Array.prototype.slice.call(arguments, 1)); | ||
}; | ||
context.clearRender = function() { | ||
module.teardownComponent(); | ||
}; | ||
}, | ||
setupContext: function() { | ||
@@ -215,0 +238,0 @@ this._super.call(this); |
@@ -131,8 +131,16 @@ import Ember from 'ember'; | ||
this.setupInject(); | ||
}, | ||
setupInject: function() { | ||
var module = this; | ||
var context = this.context; | ||
if (Ember.inject) { | ||
var keys = (Object.keys || Ember.keys)(Ember.inject); | ||
keys.forEach(function(typeName) { | ||
context.inject[typeName] = function(name, opts) { | ||
var alias = (opts && opts.as) || name; | ||
Ember.set(context, alias, context.container.lookup(typeName + ':' + name)); | ||
Ember.set(context, alias, module.container.lookup(typeName + ':' + name)); | ||
}; | ||
@@ -139,0 +147,0 @@ }); |
@@ -30,2 +30,19 @@ /* globals jQuery, self */ | ||
var _internalCheckWaiters; | ||
if (Ember.__loader.registry['ember-testing/test/waiters']) { | ||
_internalCheckWaiters = Ember.__loader.require('ember-testing/test/waiters').checkWaiters; | ||
} | ||
function checkWaiters() { | ||
if (_internalCheckWaiters) { | ||
return _internalCheckWaiters(); | ||
} else if (Ember.Test.waiters) { | ||
if (Ember.Test.waiters.any(([context, callback]) => !callback.call(context) )) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
export default function wait(_options) { | ||
@@ -47,8 +64,7 @@ var options = _options || {}; | ||
if (waitForWaiters && Ember.Test.waiters && Ember.Test.waiters.any(([context, callback]) => { | ||
return !callback.call(context); | ||
})) { | ||
if (waitForWaiters && checkWaiters()) { | ||
return; | ||
} | ||
// Stop polling | ||
@@ -55,0 +71,0 @@ self.clearInterval(watcher); |
{ | ||
"name": "ember-test-helpers", | ||
"version": "0.5.24", | ||
"version": "0.5.25", | ||
"description": "Helpers for testing Ember.js applications", | ||
@@ -5,0 +5,0 @@ "main": "lib/ember-test-helpers.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57182
21
1112