dist/ember-testing.js in ember-source-2.4.6 vs dist/ember-testing.js in ember-source-2.5.0.beta.1
- old
+ new
@@ -4,11 +4,11 @@
* @copyright Copyright 2011-2016 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 2.4.6
+ * @version 2.5.0-beta.1
*/
var enifed, requireModule, require, requirejs, Ember;
var mainContext = this;
@@ -202,15 +202,13 @@
@submodule ember-debug
*/
/**
Display a deprecation warning with the provided message and a stack trace
- (Chrome and Firefox only).
+ (Chrome and Firefox only). Ember build tools will remove any calls to
+ `Ember.deprecate()` when doing a production build.
- * In a production build, this method is defined as an empty function (NOP).
- Uses of this method in Ember itself are stripped from the ember.prod.js build.
-
@method deprecate
@param {String} message A description of the deprecation.
@param {Boolean} test A boolean. If falsy, the deprecation
will be displayed.
@param {Object} options An object that can be used to pass
@@ -259,11 +257,11 @@
var HANDLERS = {};
exports.HANDLERS = HANDLERS;
function generateTestAsFunctionDeprecation(source) {
- return 'Calling `' + source + '` with a function argument is deprecated. Please ' + 'use `!!Constructor` for constructors, or an `IIFE` to compute the test for deprecation. ' + 'In a future version functions will be treated as truthy values instead of being executed.';
+ return 'Calling `' + source + '` with a function argument is deprecated. Please ' + 'use `!!Constructor` for constructors, or an `IIFE` to compute the test for deprecation. ' + 'In a future version, functions will be treated as truthy values instead of being executed.';
}
function normalizeTest(test, source) {
if (_emberDebugIsPlainFunction.default(test)) {
_emberDebugDeprecate.default(generateTestAsFunctionDeprecation(source), false, { id: 'ember-debug.deprecate-test-as-function', until: '2.5.0' });
@@ -312,15 +310,14 @@
@class Ember
@public
*/
/**
- Define an assertion that will throw an exception if the condition is not met.
+ 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:
- * In a production build, this method is defined as an empty function (NOP).
- Uses of this method in Ember itself are stripped from the ember.prod.js build.
-
```javascript
// Test for truthiness
Ember.assert('Must pass a valid object', obj);
// Fail unconditionally
@@ -349,15 +346,13 @@
throw new _emberMetalError.default('Assertion Failed: ' + desc);
}
});
/**
- Display a debug notice.
+ Display a debug notice. Ember build tools will remove any calls to
+ `Ember.debug()` when doing a production build.
- * In a production build, this method is defined as an empty function (NOP).
- Uses of this method in Ember itself are stripped from the ember.prod.js build.
-
```javascript
Ember.debug('I\'m a debug notice!');
```
@method debug
@@ -369,13 +364,10 @@
});
/**
Display an info notice.
- * In a production build, this method is defined as an empty function (NOP).
- Uses of this method in Ember itself are stripped from the ember.prod.js build.
-
@method info
@private
*/
_emberMetalDebug.setDebugFunction('info', function info() {
_emberMetalLogger.default.info.apply(undefined, arguments);
@@ -385,21 +377,22 @@
Alias an old, deprecated method with its new counterpart.
Display a deprecation warning with the provided message and a stack trace
(Chrome and Firefox only) when the assigned method is called.
- * In a production build, this method is defined as an empty function (NOP).
+ Ember build tools will not remove calls to `Ember.deprecateFunc()`, though
+ no warnings will be shown in production.
```javascript
Ember.oldMethod = Ember.deprecateFunc('Please use the new, updated method', Ember.newMethod);
```
@method deprecateFunc
@param {String} message A description of the deprecation.
@param {Object} [options] The options object for Ember.deprecate.
@param {Function} func The new function called to replace its deprecated counterpart.
- @return {Function} a new function that wrapped the original function with a deprecation warning
+ @return {Function} A new function that wraps the original function with a deprecation warning
@private
*/
_emberMetalDebug.setDebugFunction('deprecateFunc', function deprecateFunc() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
@@ -436,15 +429,13 @@
if (typeof _ret2 === 'object') return _ret2.v;
}
});
/**
- Run a function meant for debugging.
+ Run a function meant for debugging. Ember build tools will remove any calls to
+ `Ember.runInDebug()` when doing a production build.
- * In a production build, this method is defined as an empty function (NOP).
- Uses of this method in Ember itself are stripped from the ember.prod.js build.
-
```javascript
Ember.runInDebug(() => {
Ember.Component.reopen({
didInsertElement() {
console.log("I'm happy");
@@ -479,33 +470,33 @@
@private
@method _warnIfUsingStrippedFeatureFlags
@return {void}
*/
- function _warnIfUsingStrippedFeatureFlags(FEATURES, knownFeatures, featuresWereStripped) {
+ function _warnIfUsingStrippedFeatureFlags(FEATURES, featuresWereStripped) {
if (featuresWereStripped) {
_emberMetalDebug.warn('Ember.ENV.ENABLE_OPTIONAL_FEATURES is only available in canary builds.', !_emberMetalCore.default.ENV.ENABLE_OPTIONAL_FEATURES, { id: 'ember-debug.feature-flag-with-features-stripped' });
- var keys = Object.keys(FEATURES || {});
- for (var i = 0; i < keys.length; i++) {
- var key = keys[i];
- if (key === 'isEnabled' || !(key in knownFeatures)) {
- continue;
+ for (var key in FEATURES) {
+ if (FEATURES.hasOwnProperty(key) && key !== 'isEnabled') {
+ _emberMetalDebug.warn('FEATURE["' + key + '"] is set as enabled, but FEATURE flags are only available in canary builds.', !FEATURES[key], { id: 'ember-debug.feature-flag-with-features-stripped' });
}
-
- _emberMetalDebug.warn('FEATURE["' + key + '"] is set as enabled, but FEATURE flags are only available in canary builds.', !FEATURES[key], { id: 'ember-debug.feature-flag-with-features-stripped' });
}
}
}
if (!_emberMetalCore.default.testing) {
// Complain if they're using FEATURE flags in builds other than canary
_emberMetalFeatures.FEATURES['features-stripped-test'] = true;
var featuresWereStripped = true;
+ if (_emberMetalFeatures.default('features-stripped-test')) {
+ exports.featuresWereStripped = featuresWereStripped = false;
+ }
+
delete _emberMetalFeatures.FEATURES['features-stripped-test'];
- _warnIfUsingStrippedFeatureFlags(_emberMetalCore.default.ENV.FEATURES, _emberMetalFeatures.KNOWN_FEATURES, featuresWereStripped);
+ _warnIfUsingStrippedFeatureFlags(_emberMetalCore.default.ENV.FEATURES, featuresWereStripped);
// Inform the developer about the Ember Inspector if not installed.
var isFirefox = _emberMetalEnvironment.default.isFirefox;
var isChrome = _emberMetalEnvironment.default.isChrome;
@@ -546,22 +537,22 @@
}
}
```
The handler function takes the following arguments:
<ul>
- <li> <code>message</code> - The message received from the deprecation call. </li>
+ <li> <code>message</code> - The message received from the deprecation call.</li>
<li> <code>options</code> - An object passed in with the deprecation call containing additional information including:</li>
<ul>
- <li> <code>id</code> - an id of the deprecation in the form of <code>package-name.specific-deprecation</code>.</li>
- <li> <code>until</code> - is the version number Ember the feature and deprecation will be removed in.</li>
+ <li> <code>id</code> - An id of the deprecation in the form of <code>package-name.specific-deprecation</code>.</li>
+ <li> <code>until</code> - The Ember version number the feature and deprecation will be removed in.</li>
</ul>
- <li> <code>next</code> - a function that calls into the previously registered handler.</li>
+ <li> <code>next</code> - A function that calls into the previously registered handler.</li>
</ul>
@public
@static
@method registerDeprecationHandler
- @param handler {Function} a function to handle deprecation calls
+ @param handler {Function} A function to handle deprecation calls.
@since 2.1.0
*/
_emberMetalCore.default.Debug.registerDeprecationHandler = _emberDebugDeprecate.registerHandler;
/**
Allows for runtime registration of handler functions that override the default warning behavior.
@@ -575,18 +566,18 @@
The handler function takes the following arguments:
<ul>
<li> <code>message</code> - The message received from the warn call. </li>
<li> <code>options</code> - An object passed in with the warn call containing additional information including:</li>
<ul>
- <li> <code>id</code> - an id of the warning in the form of <code>package-name.specific-warning</code>.</li>
+ <li> <code>id</code> - An id of the warning in the form of <code>package-name.specific-warning</code>.</li>
</ul>
- <li> <code>next</code> - a function that calls into the previously registered handler.</li>
+ <li> <code>next</code> - A function that calls into the previously registered handler.</li>
</ul>
@public
@static
@method registerWarnHandler
- @param handler {Function} a function to handle warnings
+ @param handler {Function} A function to handle warnings.
@since 2.1.0
*/
_emberMetalCore.default.Debug.registerWarnHandler = _emberDebugWarn.registerHandler;
/*
@@ -639,20 +630,18 @@
@module ember
@submodule ember-debug
*/
/**
- Display a warning with the provided message.
+ Display a warning with the provided message. Ember build tools will
+ remove any calls to `Ember.warn()` when doing a production build.
- * In a production build, this method is defined as an empty function (NOP).
- Uses of this method in Ember itself are stripped from the ember.prod.js build.
-
@method warn
@param {String} message A warning to display.
@param {Boolean} test An optional boolean. If falsy, the warning
will be displayed.
- @param {Object} options An ojbect that can be used to pass a unique
+ @param {Object} options An object that can be used to pass a unique
`id` for this warning. The `id` can be used by Ember debugging tools
to change the behavior (raise, log, or silence) for that specific warning.
The `id` should be namespaced by dots, e.g. "ember-debug.feature-flag-with-features-stripped"
@for Ember
@public
@@ -758,62 +747,136 @@
exception: function (error) {
ok(false, _emberMetalUtils.inspect(error));
}
});
});
-enifed('ember-testing/helpers', ['exports', 'ember-metal/property_get', 'ember-metal/error', 'ember-metal/run_loop', 'ember-views/system/jquery', 'ember-testing/test', 'ember-runtime/ext/rsvp'], function (exports, _emberMetalProperty_get, _emberMetalError, _emberMetalRun_loop, _emberViewsSystemJquery, _emberTestingTest, _emberRuntimeExtRsvp) {
+enifed('ember-testing/helpers', ['exports', 'ember-metal/property_get', 'ember-metal/error', 'ember-metal/run_loop', 'ember-views/system/jquery', 'ember-testing/test', 'ember-runtime/ext/rsvp', 'ember-metal/features'], function (exports, _emberMetalProperty_get, _emberMetalError, _emberMetalRun_loop, _emberViewsSystemJquery, _emberTestingTest, _emberRuntimeExtRsvp, _emberMetalFeatures) {
'use strict';
/**
@module ember
@submodule ember-testing
*/
var helper = _emberTestingTest.default.registerHelper;
var asyncHelper = _emberTestingTest.default.registerAsyncHelper;
- function currentRouteName(app) {
- var appController = app.__container__.lookup('controller:application');
+ var keyboardEventTypes, mouseEventTypes, buildKeyboardEvent, buildMouseEvent, buildBasicEvent, fireEvent, focus;
- return _emberMetalProperty_get.get(appController, 'currentRouteName');
- }
+ var defaultEventOptions = { canBubble: true, cancelable: true };
+ keyboardEventTypes = ['keydown', 'keypress', 'keyup'];
+ mouseEventTypes = ['click', 'mousedown', 'mouseup', 'dblclick', 'mousenter', 'mouseleave', 'mousemove', 'mouseout', 'mouseover'];
- function currentPath(app) {
- var appController = app.__container__.lookup('controller:application');
+ buildKeyboardEvent = function buildKeyboardEvent(type) {
+ var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
- return _emberMetalProperty_get.get(appController, 'currentPath');
- }
+ var event = undefined;
+ try {
+ event = document.createEvent('KeyEvents');
+ var eventOpts = _emberViewsSystemJquery.default.extend({}, defaultEventOptions, options);
+ event.initKeyEvent(type, eventOpts.canBubble, eventOpts.cancelable, window, eventOpts.ctrlKey, eventOpts.altKey, eventOpts.shiftKey, eventOpts.metaKey, eventOpts.keyCode, eventOpts.charCode);
+ } catch (e) {
+ event = buildBasicEvent(type, options);
+ }
+ return event;
+ };
- function currentURL(app) {
- var router = app.__container__.lookup('router:main');
+ buildMouseEvent = function buildMouseEvent(type) {
+ var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
- return _emberMetalProperty_get.get(router, 'location').getURL();
- }
+ var event = undefined;
+ try {
+ event = document.createEvent('MouseEvents');
+ var eventOpts = _emberViewsSystemJquery.default.extend({}, defaultEventOptions, options);
+ event.initMouseEvent(type, eventOpts.canBubble, eventOpts.cancelable, window, eventOpts.detail, eventOpts.screenX, eventOpts.screenY, eventOpts.clientX, eventOpts.clientY, eventOpts.ctrlKey, eventOpts.altKey, eventOpts.shiftKey, eventOpts.metaKey, eventOpts.button, eventOpts.relatedTarget);
+ } catch (e) {
+ event = buildBasicEvent(type, options);
+ }
+ return event;
+ };
- function pauseTest() {
- _emberTestingTest.default.adapter.asyncStart();
- return new _emberRuntimeExtRsvp.default.Promise(function () {}, 'TestAdapter paused promise');
- }
+ buildBasicEvent = function buildBasicEvent(type) {
+ var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
- function focus(el) {
- if (el && el.is(':input, [contenteditable=true]')) {
- var type = el.prop('type');
+ var event = document.createEvent('Events');
+ event.initEvent(type, true, true);
+ _emberViewsSystemJquery.default.extend(event, options);
+ return event;
+ };
+
+ fireEvent = function fireEvent(element, type) {
+ var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
+
+ if (!element) {
+ return;
+ }
+ var event = undefined;
+ if (keyboardEventTypes.indexOf(type) > -1) {
+ event = buildKeyboardEvent(type, options);
+ } else if (mouseEventTypes.indexOf(type) > -1) {
+ var rect = element.getBoundingClientRect();
+ var x = rect.left + 1;
+ var y = rect.top + 1;
+ var simulatedCoordinates = {
+ screenX: x + 5,
+ screenY: y + 95,
+ clientX: x,
+ clientY: y
+ };
+ event = buildMouseEvent(type, _emberViewsSystemJquery.default.extend(simulatedCoordinates, options));
+ } else {
+ event = buildBasicEvent(type, options);
+ }
+ element.dispatchEvent(event);
+ };
+
+ focus = function focus(el) {
+ if (!el) {
+ return;
+ }
+ var $el = _emberViewsSystemJquery.default(el);
+ if ($el.is(':input, [contenteditable=true]')) {
+ var type = $el.prop('type');
if (type !== 'checkbox' && type !== 'radio' && type !== 'hidden') {
- _emberMetalRun_loop.default(el, function () {
+ _emberMetalRun_loop.default(null, 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();
+ el.focus();
} else {
- this.trigger('focusin');
+ $el.trigger('focusin');
}
});
}
}
+ };
+
+ function currentRouteName(app) {
+ var routingService = app.__container__.lookup('service:-routing');
+
+ return _emberMetalProperty_get.get(routingService, 'currentRouteName');
}
+ function currentPath(app) {
+ var routingService = app.__container__.lookup('service:-routing');
+
+ return _emberMetalProperty_get.get(routingService, 'currentPath');
+ }
+
+ function currentURL(app) {
+ var router = app.__container__.lookup('router:main');
+
+ return _emberMetalProperty_get.get(router, 'location').getURL();
+ }
+
+ function pauseTest() {
+ _emberTestingTest.default.adapter.asyncStart();
+ return new _emberRuntimeExtRsvp.default.Promise(function () {}, 'TestAdapter paused promise');
+ }
+
function visit(app, url) {
var router = app.__container__.lookup('router:main');
var shouldHandleURL = false;
app.boot().then(function () {
@@ -835,17 +898,19 @@
return app.testHelpers.wait();
}
function click(app, selector, context) {
var $el = app.testHelpers.findWithAssert(selector, context);
- _emberMetalRun_loop.default($el, 'mousedown');
+ var el = $el[0];
- focus($el);
+ _emberMetalRun_loop.default(null, fireEvent, el, 'mousedown');
- _emberMetalRun_loop.default($el, 'mouseup');
- _emberMetalRun_loop.default($el, 'click');
+ focus(el);
+ _emberMetalRun_loop.default(null, fireEvent, el, 'mouseup');
+ _emberMetalRun_loop.default(null, fireEvent, el, 'click');
+
return app.testHelpers.wait();
}
function triggerEvent(app, selector, contextOrType, typeOrOptions, possibleOptions) {
var arity = arguments.length;
@@ -877,15 +942,14 @@
type = typeOrOptions;
options = possibleOptions;
}
var $el = app.testHelpers.findWithAssert(selector, context);
+ var el = $el[0];
- var event = _emberViewsSystemJquery.default.Event(type, options);
+ _emberMetalRun_loop.default(null, fireEvent, el, type, options);
- _emberMetalRun_loop.default($el, 'trigger', event);
-
return app.testHelpers.wait();
}
function keyEvent(app, selector, contextOrType, typeOrKeyCode, keyCode) {
var context, type;
@@ -901,22 +965,23 @@
return app.testHelpers.triggerEvent(selector, context, type, { keyCode: keyCode, which: keyCode });
}
function fillIn(app, selector, contextOrText, text) {
- var $el, context;
+ var $el, el, context;
if (typeof text === 'undefined') {
text = contextOrText;
} else {
context = contextOrText;
}
$el = app.testHelpers.findWithAssert(selector, context);
- focus($el);
+ el = $el[0];
+ focus(el);
_emberMetalRun_loop.default(function () {
$el.val(text);
- $el.trigger('input');
- $el.change();
+ fireEvent(el, 'input');
+ fireEvent(el, 'change');
});
return app.testHelpers.wait();
}
function findWithAssert(app, selector, context) {
@@ -939,14 +1004,14 @@
return app.testHelpers.wait(callback(app));
}
function wait(app, value) {
return new _emberRuntimeExtRsvp.default.Promise(function (resolve) {
+ var router = app.__container__.lookup('router:main');
+
// Every 10ms, poll for the async thing to have finished
var watcher = setInterval(function () {
- 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;
}
@@ -1223,9 +1288,13 @@
@since 1.5.0
@public
*/
asyncHelper('triggerEvent', triggerEvent);
});
+
+// 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.
enifed('ember-testing/index', ['exports', 'ember-metal/core', 'ember-testing/initializers', 'ember-testing/support', 'ember-testing/setup_for_testing', 'ember-testing/test', 'ember-testing/adapters/adapter', 'ember-testing/adapters/qunit', 'ember-testing/helpers'], function (exports, _emberMetalCore, _emberTestingInitializers, _emberTestingSupport, _emberTestingSetup_for_testing, _emberTestingTest, _emberTestingAdaptersAdapter, _emberTestingAdaptersQunit, _emberTestingHelpers) {
'use strict';
// adds helpers to helpers object in Test