diff --git a/packages/ember-debug/lib/handlers.js b/packages/ember-debug/lib/handlers.js index dc82e9cb956..7d7fbef1a6a 100644 --- a/packages/ember-debug/lib/handlers.js +++ b/packages/ember-debug/lib/handlers.js @@ -1,28 +1,5 @@ -import isPlainFunction from 'ember-debug/is-plain-function'; -import deprecate from 'ember-debug/deprecate'; - export let HANDLERS = { }; -export 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.`; -} - -function normalizeTest(test, source) { - if (isPlainFunction(test)) { - deprecate( - generateTestAsFunctionDeprecation(source), - false, - { id: 'ember-debug.deprecate-test-as-function', until: '2.5.0' } - ); - - return test(); - } - - return test; -} - export function registerHandler(type, callback) { let nextHandler = HANDLERS[type] || function() { }; @@ -32,7 +9,7 @@ export function registerHandler(type, callback) { } export function invoke(type, message, test, options) { - if (normalizeTest(test, 'Ember.' + type)) { return; } + if (test) { return; } let handlerForType = HANDLERS[type]; diff --git a/packages/ember-debug/lib/index.js b/packages/ember-debug/lib/index.js index 829ed035ce3..582cfd30898 100644 --- a/packages/ember-debug/lib/index.js +++ b/packages/ember-debug/lib/index.js @@ -15,8 +15,6 @@ import _deprecate, { import _warn, { registerHandler as registerWarnHandler } from 'ember-debug/warn'; -import isPlainFunction from 'ember-debug/is-plain-function'; -import { generateTestAsFunctionDeprecation } from 'ember-debug/handlers'; /** @module ember @@ -51,21 +49,7 @@ import { generateTestAsFunctionDeprecation } from 'ember-debug/handlers'; @public */ setDebugFunction('assert', function assert(desc, test) { - let throwAssertion; - - if (isPlainFunction(test)) { - deprecate( - generateTestAsFunctionDeprecation('Ember.assert'), - false, - { id: 'ember-debug.deprecate-test-as-function', until: '2.5.0' } - ); - - throwAssertion = !test(); - } else { - throwAssertion = !test; - } - - if (throwAssertion) { + if (!test) { throw new EmberError('Assertion Failed: ' + desc); } }); diff --git a/packages/ember-debug/lib/is-plain-function.js b/packages/ember-debug/lib/is-plain-function.js deleted file mode 100644 index 925741604e3..00000000000 --- a/packages/ember-debug/lib/is-plain-function.js +++ /dev/null @@ -1,3 +0,0 @@ -export default function isPlainFunction(test) { - return typeof test === 'function' && test.PrototypeMixin === undefined; -} diff --git a/packages/ember-debug/tests/main_test.js b/packages/ember-debug/tests/main_test.js index 693a70c8308..c5d09ceb2b6 100644 --- a/packages/ember-debug/tests/main_test.js +++ b/packages/ember-debug/tests/main_test.js @@ -1,6 +1,6 @@ import Ember from 'ember-metal/core'; import EmberObject from 'ember-runtime/system/object'; -import { HANDLERS, generateTestAsFunctionDeprecation } from 'ember-debug/handlers'; +import { HANDLERS } from 'ember-debug/handlers'; import { registerHandler, missingOptionsDeprecation, @@ -13,7 +13,6 @@ import { missingOptionsDeprecation as missingWarnOptionsDeprecation, registerHandler as registerWarnHandler } from 'ember-debug/warn'; -import deprecate from 'ember-debug/deprecate'; let originalEnvValue; let originalDeprecateHandler; @@ -107,21 +106,14 @@ QUnit.test('Ember.deprecate throws deprecation if second argument is falsy', fun }); }); -QUnit.test('Ember.deprecate throws deprecation if second argument is a function and it returns true', function(assert) { - assert.expect(1); +QUnit.test('Ember.deprecate does not invoke a function as the second argument', function() { + expect(1); - throws(() => { - Ember.deprecate('This deprecation is not thrown, but argument deprecation is thrown', () => true, { id: 'test', until: 'forever' }); - }); -}); + Ember.deprecate('Deprecation is thrown', function() { + ok(false, 'this function should not be invoked'); + }, { id: 'test', until: 'forever' }); -QUnit.test('Ember.deprecate throws if second argument is a function and it returns false', function() { - expect(1); - throws(function() { - Ember.deprecate('Deprecation is thrown', function() { - return false; - }, { id: 'test', until: 'forever' }); - }); + ok(true, 'deprecations were not thrown'); }); QUnit.test('Ember.deprecate does not throw deprecations if second argument is truthy', function() { @@ -150,23 +142,12 @@ QUnit.test('Ember.assert throws if second argument is falsy', function() { }); }); -QUnit.test('Ember.assert does not throw if second argument is a function and it returns true', function(assert) { +QUnit.test('Ember.assert does not throw if second argument is a function', function(assert) { assert.expect(1); - // Shouldn't trigger an assertion, but deprecation from using function as test is expected. - expectDeprecation( - () => Ember.assert('Assertion is thrown', () => true), - generateTestAsFunctionDeprecation('Ember.assert') - ); -}); + Ember.assert('Assertion is thrown', () => true); -QUnit.test('Ember.assert throws if second argument is a function and it returns false', function() { - expect(1); - throws(function() { - Ember.assert('Assertion is thrown', function() { - return false; - }); - }); + ok(true, 'assertions were not thrown'); }); QUnit.test('Ember.assert does not throw if second argument is truthy', function() { @@ -298,39 +279,3 @@ QUnit.test('Ember.warn without options.id triggers a deprecation', function(asse Ember.warn('foo', false, { }); }); - -QUnit.test('Ember.deprecate triggers a deprecation when test argument is a function', function(assert) { - assert.expect(1); - - registerHandler(message => assert.equal( - message, - generateTestAsFunctionDeprecation('Ember.deprecate'), - 'proper deprecation is triggered when test argument is a function' - )); - - deprecate('Deprecation is thrown', () => true, { id: 'test', until: 'forever' }); -}); - -QUnit.test('Ember.warn triggers a deprecation when test argument is a function', function(assert) { - assert.expect(1); - - registerHandler(message => assert.equal( - message, - generateTestAsFunctionDeprecation('Ember.warn'), - 'proper deprecation is triggered when test argument is a function' - )); - - Ember.warn('Warning is thrown', () => true, { id: 'test' }); -}); - -QUnit.test('Ember.assert triggers a deprecation when test argument is a function', function(assert) { - assert.expect(1); - - registerHandler(message => assert.equal( - message, - generateTestAsFunctionDeprecation('Ember.assert'), - 'proper deprecation is triggered when test argument is a function' - )); - - Ember.assert('Assertion is thrown', () => true); -});