dist/ember-testing.js in ember-source-1.12.2 vs dist/ember-testing.js in ember-source-1.13.0.beta.1

- old
+ new

@@ -3,11 +3,11 @@ * @copyright Copyright 2011-2015 Tilde Inc. and contributors * Portions Copyright 2006-2011 Strobe Inc. * Portions Copyright 2008-2011 Apple Inc. All rights reserved. * @license Licensed under MIT license * See https://raw.github.com/emberjs/ember.js/master/LICENSE - * @version 1.12.2 + * @version 1.13.0-beta.1 */ (function() { var enifed, requireModule, eriuqer, requirejs, Ember; var mainContext = this; @@ -108,20 +108,54 @@ enifed = Ember.__loader.define; requirejs = eriuqer = requireModule = Ember.__loader.require; } })(); -enifed('ember-debug', ['exports', 'ember-metal/core', 'ember-metal/utils', 'ember-metal/error', 'ember-metal/logger', 'ember-metal/environment'], function (exports, Ember, utils, EmberError, Logger, environment) { +enifed('ember-debug', ['exports', 'ember-metal/core', 'ember-metal/error', 'ember-metal/logger', 'ember-metal/environment'], function (exports, Ember, EmberError, Logger, environment) { 'use strict'; exports._warnIfUsingStrippedFeatureFlags = _warnIfUsingStrippedFeatureFlags; + /** + Will call `Ember.warn()` if ENABLE_ALL_FEATURES, ENABLE_OPTIONAL_FEATURES, or + any specific FEATURES flag is truthy. + + This method is called automatically in debug canary builds. + + @private + @method _warnIfUsingStrippedFeatureFlags + @return {void} + */ + function isPlainFunction(test) { + return typeof test === "function" && test.PrototypeMixin === undefined; + } + + /** + Define an assertion that will throw an exception if the condition is not + met. Ember build tools will remove any calls to `Ember.assert()` when + doing a production build. Example: + + ```javascript + // Test for truthiness + Ember.assert('Must pass a valid object', obj); + + // Fail unconditionally + Ember.assert('This code path should never be run'); + ``` + + @method assert + @param {String} desc A description of the assertion. This will become + the text of the Error thrown if the assertion fails. + @param {Boolean|Function} test Must be truthy for the assertion to pass. If + falsy, an exception will be thrown. If this is a function, it will be executed and + its return value will be used as condition. + */ Ember['default'].assert = function (desc, test) { var throwAssertion; - if (utils.typeOf(test) === 'function') { + if (isPlainFunction(test)) { throwAssertion = !test(); } else { throwAssertion = !test; } @@ -140,11 +174,11 @@ will be displayed. */ Ember['default'].warn = function (message, test) { if (!test) { Logger['default'].warn("WARNING: " + message); - if ('trace' in Logger['default']) { + if ("trace" in Logger['default']) { Logger['default'].trace(); } } }; @@ -177,11 +211,11 @@ in a `url` to the transition guide on the emberjs.com website. */ Ember['default'].deprecate = function (message, test, options) { var noDeprecation; - if (typeof test === 'function') { + if (isPlainFunction(test)) { noDeprecation = test(); } else { noDeprecation = test; } @@ -201,27 +235,27 @@ } catch (e) { error = e; } if (arguments.length === 3) { - Ember['default'].assert('options argument to Ember.deprecate should be an object', options && typeof options === 'object'); + Ember['default'].assert("options argument to Ember.deprecate should be an object", options && typeof options === "object"); if (options.url) { - message += ' See ' + options.url + ' for more details.'; + message += " See " + options.url + " for more details."; } } if (Ember['default'].LOG_STACKTRACE_ON_DEPRECATION && error.stack) { var stack; - var stackStr = ''; + var stackStr = ""; - if (error['arguments']) { + if (error["arguments"]) { // Chrome - stack = error.stack.replace(/^\s+at\s+/gm, '').replace(/^([^\(]+?)([\n$])/gm, '{anonymous}($1)$2').replace(/^Object.<anonymous>\s*\(([^\)]+)\)/gm, '{anonymous}($1)').split('\n'); + stack = error.stack.replace(/^\s+at\s+/gm, "").replace(/^([^\(]+?)([\n$])/gm, "{anonymous}($1)$2").replace(/^Object.<anonymous>\s*\(([^\)]+)\)/gm, "{anonymous}($1)").split("\n"); stack.shift(); } else { // Firefox - stack = error.stack.replace(/(?:\n@:0)?\s+$/m, '').replace(/^\(/gm, '{anonymous}(').split('\n'); + stack = error.stack.replace(/(?:\n@:0)?\s+$/m, "").replace(/^\(/gm, "{anonymous}(").split("\n"); } stackStr = "\n " + stack.slice(2).join("\n "); message = message + stackStr; } @@ -273,60 +307,48 @@ @since 1.5.0 */ Ember['default'].runInDebug = function (func) { func(); }; - - /** - Will call `Ember.warn()` if ENABLE_ALL_FEATURES, ENABLE_OPTIONAL_FEATURES, or - any specific FEATURES flag is truthy. - - This method is called automatically in debug canary builds. - - @private - @method _warnIfUsingStrippedFeatureFlags - @return {void} - */ - function _warnIfUsingStrippedFeatureFlags(FEATURES, featuresWereStripped) { if (featuresWereStripped) { - Ember['default'].warn('Ember.ENV.ENABLE_ALL_FEATURES is only available in canary builds.', !Ember['default'].ENV.ENABLE_ALL_FEATURES); - Ember['default'].warn('Ember.ENV.ENABLE_OPTIONAL_FEATURES is only available in canary builds.', !Ember['default'].ENV.ENABLE_OPTIONAL_FEATURES); + Ember['default'].warn("Ember.ENV.ENABLE_ALL_FEATURES is only available in canary builds.", !Ember['default'].ENV.ENABLE_ALL_FEATURES); + Ember['default'].warn("Ember.ENV.ENABLE_OPTIONAL_FEATURES is only available in canary builds.", !Ember['default'].ENV.ENABLE_OPTIONAL_FEATURES); for (var key in FEATURES) { - if (FEATURES.hasOwnProperty(key) && key !== 'isEnabled') { - Ember['default'].warn('FEATURE["' + key + '"] is set as enabled, but FEATURE flags are only available in canary builds.', !FEATURES[key]); + if (FEATURES.hasOwnProperty(key) && key !== "isEnabled") { + Ember['default'].warn("FEATURE[\"" + key + "\"] is set as enabled, but FEATURE flags are only available in canary builds.", !FEATURES[key]); } } } } if (!Ember['default'].testing) { // Complain if they're using FEATURE flags in builds other than canary - Ember['default'].FEATURES['features-stripped-test'] = true; + Ember['default'].FEATURES["features-stripped-test"] = true; var featuresWereStripped = true; - delete Ember['default'].FEATURES['features-stripped-test']; + delete Ember['default'].FEATURES["features-stripped-test"]; _warnIfUsingStrippedFeatureFlags(Ember['default'].ENV.FEATURES, featuresWereStripped); // Inform the developer about the Ember Inspector if not installed. - var isFirefox = typeof InstallTrigger !== 'undefined'; + var isFirefox = environment['default'].isFirefox; var isChrome = environment['default'].isChrome; - if (typeof window !== 'undefined' && (isFirefox || isChrome) && window.addEventListener) { + if (typeof window !== "undefined" && (isFirefox || isChrome) && window.addEventListener) { window.addEventListener("load", function () { if (document.documentElement && document.documentElement.dataset && !document.documentElement.dataset.emberExtension) { var downloadURL; if (isChrome) { - downloadURL = 'https://chrome.google.com/webstore/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi'; + downloadURL = "https://chrome.google.com/webstore/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi"; } else if (isFirefox) { - downloadURL = 'https://addons.mozilla.org/en-US/firefox/addon/ember-inspector/'; + downloadURL = "https://addons.mozilla.org/en-US/firefox/addon/ember-inspector/"; } - Ember['default'].debug('For more advanced debugging, install the Ember Inspector from ' + downloadURL); + Ember['default'].debug("For more advanced debugging, install the Ember Inspector from " + downloadURL); } }, false); } } @@ -338,11 +360,11 @@ so that if `ember.js` (which must be output for backwards compat reasons) is used a nice helpful warning message will be printed out. */ var runningNonEmberDebugJS = false; if (runningNonEmberDebugJS) { - Ember['default'].warn('Please use `ember.debug.js` instead of `ember.js` for development and debugging.'); + Ember['default'].warn("Please use `ember.debug.js` instead of `ember.js` for development and debugging."); } exports.runningNonEmberDebugJS = runningNonEmberDebugJS; }); @@ -438,99 +460,97 @@ var helper = Test['default'].registerHelper; var asyncHelper = Test['default'].registerAsyncHelper; function currentRouteName(app) { - var appController = app.__container__.lookup('controller:application'); + var appController = app.__container__.lookup("controller:application"); - return property_get.get(appController, 'currentRouteName'); + return property_get.get(appController, "currentRouteName"); } function currentPath(app) { - var appController = app.__container__.lookup('controller:application'); + var appController = app.__container__.lookup("controller:application"); - return property_get.get(appController, 'currentPath'); + return property_get.get(appController, "currentPath"); } function currentURL(app) { - var router = app.__container__.lookup('router:main'); + var router = app.__container__.lookup("router:main"); - return property_get.get(router, 'location').getURL(); + return property_get.get(router, "location").getURL(); } function pauseTest() { Test['default'].adapter.asyncStart(); - return new Ember['default'].RSVP.Promise(function () {}, 'TestAdapter paused promise'); + return new Ember['default'].RSVP.Promise(function () {}, "TestAdapter paused promise"); } function focus(el) { - if (el && el.is(':input, [contenteditable=true]')) { - var type = el.prop('type'); - if (type !== 'checkbox' && type !== 'radio' && type !== 'hidden') { + if (el && el.is(":input, [contenteditable=true]")) { + var type = el.prop("type"); + if (type !== "checkbox" && type !== "radio" && type !== "hidden") { run['default'](el, function () { // Firefox does not trigger the `focusin` event if the window // does not have focus. If the document doesn't have focus just // use trigger('focusin') instead. if (!document.hasFocus || document.hasFocus()) { this.focus(); } else { - this.trigger('focusin'); + this.trigger("focusin"); } }); } } } function visit(app, url) { - var router = app.__container__.lookup('router:main'); - app.boot().then(function () { - router.location.setURL(url); - }); + var router = app.__container__.lookup("router:main"); if (app._readinessDeferrals > 0) { - router['initialURL'] = url; - run['default'](app, 'advanceReadiness'); - delete router['initialURL']; + router["initialURL"] = url; + run['default'](app, "advanceReadiness"); + delete router["initialURL"]; } else { - run['default'](app.__deprecatedInstance__, 'handleURL', url); + router.location.setURL(url); + run['default'](app.__deprecatedInstance__, "handleURL", url); } return app.testHelpers.wait(); } function click(app, selector, context) { var $el = app.testHelpers.findWithAssert(selector, context); - run['default']($el, 'mousedown'); + run['default']($el, "mousedown"); focus($el); - run['default']($el, 'mouseup'); - run['default']($el, 'click'); + run['default']($el, "mouseup"); + run['default']($el, "click"); return app.testHelpers.wait(); } function check(app, selector, context) { var $el = app.testHelpers.findWithAssert(selector, context); - var type = $el.prop('type'); + var type = $el.prop("type"); - Ember['default'].assert('To check \'' + selector + '\', the input must be a checkbox', type === 'checkbox'); + Ember['default'].assert("To check '" + selector + "', the input must be a checkbox", type === "checkbox"); - if (!$el.prop('checked')) { + if (!$el.prop("checked")) { app.testHelpers.click(selector, context); } return app.testHelpers.wait(); } function uncheck(app, selector, context) { var $el = app.testHelpers.findWithAssert(selector, context); - var type = $el.prop('type'); + var type = $el.prop("type"); - Ember['default'].assert('To uncheck \'' + selector + '\', the input must be a checkbox', type === 'checkbox'); + Ember['default'].assert("To uncheck '" + selector + "', the input must be a checkbox", type === "checkbox"); - if ($el.prop('checked')) { + if ($el.prop("checked")) { app.testHelpers.click(selector, context); } return app.testHelpers.wait(); } @@ -568,19 +588,19 @@ var $el = app.testHelpers.findWithAssert(selector, context); var event = jQuery['default'].Event(type, options); - run['default']($el, 'trigger', event); + run['default']($el, "trigger", event); return app.testHelpers.wait(); } function keyEvent(app, selector, contextOrType, typeOrKeyCode, keyCode) { var context, type; - if (typeof keyCode === 'undefined') { + if (typeof keyCode === "undefined") { context = null; keyCode = typeOrKeyCode; type = contextOrType; } else { context = contextOrType; @@ -590,11 +610,11 @@ return app.testHelpers.triggerEvent(selector, context, type, { keyCode: keyCode, which: keyCode }); } function fillIn(app, selector, contextOrText, text) { var $el, context; - if (typeof text === 'undefined') { + if (typeof text === "undefined") { text = contextOrText; } else { context = contextOrText; } $el = app.testHelpers.findWithAssert(selector, context); @@ -613,11 +633,11 @@ return $el; } function find(app, selector, context) { var $el; - context = context || property_get.get(app, 'rootElement'); + context = context || property_get.get(app, "rootElement"); $el = app.$(selector, context); return $el; } @@ -627,11 +647,11 @@ function wait(app, value) { return new RSVP['default'].Promise(function (resolve) { // Every 10ms, poll for the async thing to have finished var watcher = setInterval(function () { - var router = app.__container__.lookup('router:main'); + var router = app.__container__.lookup("router:main"); // 1. If the router is loading, keep polling var routerIsLoading = router.router && !!router.router.activeTransition; if (routerIsLoading) { return; @@ -677,11 +697,11 @@ * * @method visit * @param {String} url the name of the route * @return {RSVP.Promise} */ - asyncHelper('visit', visit); + asyncHelper("visit", visit); /** * Clicks an element and triggers any actions triggered by the element's `click` * event. * @@ -695,11 +715,11 @@ * * @method click * @param {String} selector jQuery selector for finding element on the DOM * @return {RSVP.Promise} */ - asyncHelper('click', click); + asyncHelper("click", click); /** * Simulates a key event, e.g. `keypress`, `keydown`, `keyup` with the desired keyCode * * Example: @@ -715,11 +735,11 @@ * @param {String} type the type of key event, e.g. `keypress`, `keydown`, `keyup` * @param {Number} keyCode the keyCode of the simulated key event * @return {RSVP.Promise} * @since 1.5.0 */ - asyncHelper('keyEvent', keyEvent); + asyncHelper("keyEvent", keyEvent); /** * Fills in an input element with some text. * * Example: @@ -734,11 +754,11 @@ * @param {String} selector jQuery selector finding an input element on the DOM * to fill text with * @param {String} text text to place inside the input element * @return {RSVP.Promise} */ - asyncHelper('fillIn', fillIn); + asyncHelper("fillIn", fillIn); /** * Finds an element in the context of the app's container element. A simple alias * for `app.$(selector)`. * @@ -750,11 +770,11 @@ * * @method find * @param {String} selector jQuery string selector for element lookup * @return {Object} jQuery object representing the results of the query */ - helper('find', find); + helper("find", find); /** * Like `find`, but throws an error if the element selector returns no results. * * Example: @@ -767,11 +787,11 @@ * @param {String} selector jQuery selector string for finding an element within * the DOM * @return {Object} jQuery object representing the results of the query * @throws {Error} throws error if jQuery object returned has a length of 0 */ - helper('findWithAssert', findWithAssert); + helper("findWithAssert", findWithAssert); /** Causes the run loop to process any pending events. This is used to ensure that any async operations from other helpers (or your assertions) have been processed. @@ -792,12 +812,12 @@ @method wait @param {Object} value The value to be returned. @return {RSVP.Promise} */ - asyncHelper('wait', wait); - asyncHelper('andThen', andThen); + asyncHelper("wait", wait); + asyncHelper("andThen", andThen); /** Returns the currently active route name. Example: @@ -812,11 +832,11 @@ @method currentRouteName @return {Object} The name of the currently active route. @since 1.5.0 */ - helper('currentRouteName', currentRouteName); + helper("currentRouteName", currentRouteName); /** Returns the current path. Example: @@ -831,11 +851,11 @@ @method currentPath @return {Object} The currently active path. @since 1.5.0 */ - helper('currentPath', currentPath); + helper("currentPath", currentPath); /** Returns the current URL. Example: @@ -850,11 +870,11 @@ @method currentURL @return {Object} The currently active URL. @since 1.5.0 */ - helper('currentURL', currentURL); + helper("currentURL", currentURL); /** Pauses the current test - this is useful for debugging while testing or for test-driving. It allows you to inspect the state of your application at any point. @@ -869,11 +889,11 @@ @since 1.9.0 @method pauseTest @return {Object} A promise that will never resolve */ - helper('pauseTest', pauseTest); + helper("pauseTest", pauseTest); /** Triggers the given DOM event on the element identified by the provided selector. Example: @@ -895,11 +915,11 @@ @param {String} type The event type to be triggered. @param {Object} [options] The options to be passed to jQuery.Event. @return {RSVP.Promise} @since 1.5.0 */ - asyncHelper('triggerEvent', triggerEvent); + asyncHelper("triggerEvent", triggerEvent); }); enifed('ember-testing/initializers', ['ember-runtime/system/lazy_load'], function (lazy_load) { 'use strict'; @@ -924,10 +944,22 @@ enifed('ember-testing/setup_for_testing', ['exports', 'ember-metal/core', 'ember-testing/adapters/qunit', 'ember-views/system/jquery'], function (exports, Ember, QUnitAdapter, jQuery) { 'use strict'; + + /** + Sets Ember up for testing. This is useful to perform + basic setup steps in order to unit test. + + Use `App.setupForTesting` to perform integration tests (full + application testing). + + @method setupForTesting + @namespace Ember + @since 1.5.0 + */ exports['default'] = setupForTesting; var Test, requests; function incrementAjaxPendingRequests(_, xhr) { requests.push(xhr); @@ -940,25 +972,13 @@ requests.splice(i, 1); } } Test.pendingAjaxRequests = requests.length; } - - /** - Sets Ember up for testing. This is useful to perform - basic setup steps in order to unit test. - - Use `App.setupForTesting` to perform integration tests (full - application testing). - - @method setupForTesting - @namespace Ember - @since 1.5.0 - */ function setupForTesting() { if (!Test) { - Test = requireModule('ember-testing/test')['default']; + Test = requireModule("ember-testing/test")["default"]; } Ember['default'].testing = true; // if adapter is not manually set default to QUnit @@ -967,14 +987,14 @@ } requests = []; Test.pendingAjaxRequests = requests.length; - jQuery['default'](document).off('ajaxSend', incrementAjaxPendingRequests); - jQuery['default'](document).off('ajaxComplete', decrementAjaxPendingRequests); - jQuery['default'](document).on('ajaxSend', incrementAjaxPendingRequests); - jQuery['default'](document).on('ajaxComplete', decrementAjaxPendingRequests); + jQuery['default'](document).off("ajaxSend", incrementAjaxPendingRequests); + jQuery['default'](document).off("ajaxComplete", decrementAjaxPendingRequests); + jQuery['default'](document).on("ajaxSend", incrementAjaxPendingRequests); + jQuery['default'](document).on("ajaxComplete", decrementAjaxPendingRequests); } }); enifed('ember-testing/support', ['ember-metal/core', 'ember-views/system/jquery', 'ember-metal/environment'], function (Ember, jQuery, environment) { @@ -989,11 +1009,11 @@ @private @method testCheckboxClick */ function testCheckboxClick(handler) { - $('<input type="checkbox">').css({ position: 'absolute', left: '-1000px', top: '-1000px' }).appendTo('body').on('click', handler).trigger('click').remove(); + $("<input type=\"checkbox\">").css({ position: "absolute", left: "-1000px", top: "-1000px" }).appendTo("body").on("click", handler).trigger("click").remove(); } if (environment['default'].hasDOM) { $(function () { /* @@ -1355,10 +1375,10 @@ setupForTesting['default'](); this.testing = true; this.Router.reopen({ - location: 'none' + location: "none" }); }, /** This will be used as the container to inject the test helpers into. By \ No newline at end of file