ember-qunit
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -9,3 +9,3 @@ "use strict"; | ||
moduleFor('component:' + name, description, callbacks, function(container, context) { | ||
moduleFor('component:' + name, description, callbacks, function(container, context, defaultSubject) { | ||
var templateName = 'template:components/' + name; | ||
@@ -19,2 +19,5 @@ | ||
} | ||
context.dispatcher = Ember.EventDispatcher.create(); | ||
context.dispatcher.setup({}, '#ember-testing'); | ||
@@ -27,3 +30,3 @@ context.__setup_properties__.append = function(selector) { | ||
// TODO: destory this somewhere | ||
containerView.appendTo(Ember.$('#ember-testing')[0]); | ||
containerView.appendTo('#ember-testing'); | ||
return subject; | ||
@@ -30,0 +33,0 @@ }); |
@@ -16,3 +16,3 @@ "use strict"; | ||
if (context.__setup_properties__.subject === defaultSubject) { | ||
context.__setup_properties__.subject = function(factory, options) { | ||
context.__setup_properties__.subject = function(options) { | ||
return Ember.run(function() { | ||
@@ -19,0 +19,0 @@ return container.lookup('store:main').createRecord(name, options); |
"use strict"; | ||
var Ember = require("ember")["default"] || require("ember"); | ||
var QUnit = require("qunit")["default"] || require("qunit"); | ||
//import QUnit from 'qunit'; // Assumed global in runner | ||
var testContext = require("./test-context")["default"] || require("./test-context"); | ||
@@ -8,40 +8,38 @@ var isolatedContainer = require("./isolated-container")["default"] || require("./isolated-container"); | ||
exports["default"] = function moduleFor(fullName, description, callbacks, delegate) { | ||
callbacks = callbacks || { }; | ||
var container; | ||
var context; | ||
var _callbacks = { | ||
setup: function(){ | ||
callbacks = callbacks || { }; | ||
var needs = [fullName].concat(callbacks.needs || []); | ||
var container = isolatedContainer(needs); | ||
var needs = [fullName].concat(callbacks.needs || []); | ||
container = isolatedContainer(needs); | ||
callbacks.subject = callbacks.subject || defaultSubject; | ||
callbacks.subject = callbacks.subject || defaultSubject; | ||
callbacks.setup = callbacks.setup || function() { }; | ||
callbacks.teardown = callbacks.teardown || function() { }; | ||
callbacks.setup = callbacks.setup || function() { }; | ||
callbacks.teardown = callbacks.teardown || function() { }; | ||
function factory() { | ||
return container.lookupFactory(fullName); | ||
} | ||
testContext.set({ | ||
container: container, | ||
factory: factory, | ||
dispatcher: null, | ||
__setup_properties__: callbacks | ||
}); | ||
context = testContext.get(); | ||
function factory() { | ||
return container.lookupFactory(fullName); | ||
} | ||
function subject(options) { | ||
return callbacks.subject(factory(), options); | ||
} | ||
testContext.set({ | ||
container: container, | ||
subject: subject, | ||
factory: factory, | ||
__setup_properties__: callbacks | ||
}); | ||
if (delegate) { | ||
delegate(container, testContext.get(), defaultSubject); | ||
} | ||
var context = testContext.get(); | ||
// TODO: move this to component|view callbacks when infrastructure is added | ||
// to make it simpler | ||
var dispatcher = Ember.EventDispatcher.create(); | ||
var _callbacks = { | ||
setup: function(){ | ||
container = isolatedContainer(needs); | ||
dispatcher.setup(); | ||
Ember.$('<div id="ember-testing"/>').appendTo(document.body); | ||
if (delegate) { | ||
delegate(container, context, defaultSubject); | ||
} | ||
if (Ember.$('#ember-testing').length === 0) { | ||
Ember.$('<div id="ember-testing"/>').appendTo(document.body); | ||
} | ||
buildContextVariables(context); | ||
@@ -54,6 +52,10 @@ callbacks.setup.call(context, container); | ||
container.destroy(); | ||
dispatcher.destroy(); | ||
if (context.dispatcher) { | ||
context.dispatcher.destroy(); | ||
} | ||
}); | ||
callbacks.teardown(container); | ||
Ember.$('#ember-testing').empty(); | ||
callbacks.teardown(container); | ||
} | ||
@@ -65,3 +67,3 @@ }; | ||
function defaultSubject(factory, options) { | ||
function defaultSubject(options, factory) { | ||
return factory.create(options); | ||
@@ -72,7 +74,7 @@ } | ||
function buildContextVariables(context) { | ||
var cache = { }; | ||
var cache = { }; | ||
var callbacks = context.__setup_properties__; | ||
var factory = context.factory; | ||
var container = context.container; | ||
var factory = context.factory; | ||
Ember.keys(callbacks).filter(function(key){ | ||
@@ -83,7 +85,5 @@ // ignore the default setup/teardown keys | ||
context[key] = function(options) { | ||
if (cache[key]) { | ||
return cache[key]; | ||
} | ||
if (cache[key]) { return cache[key]; } | ||
var result = callbacks[key](factory(), options, container); | ||
var result = callbacks[key](options, factory(), container); | ||
cache[key] = result; | ||
@@ -90,0 +90,0 @@ return result; |
"use strict"; | ||
var Ember = require("ember")["default"] || require("ember"); | ||
var QUnit = require("qunit")["default"] || require("qunit"); | ||
//import QUnit from 'qunit'; // Assumed global in runner | ||
var testContext = require("./test-context")["default"] || require("./test-context"); | ||
@@ -11,5 +11,6 @@ | ||
exports["default"] = function test(testName, callback) { | ||
var context = testContext.get(); // save refence | ||
function wrapper() { | ||
var context = testContext.get(); | ||
resetViews(); | ||
@@ -16,0 +17,0 @@ var result = callback.call(context); |
{ | ||
"name": "ember-qunit", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "unit test helpers for ember", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/main.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
13392
13
193