Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLEANUP beta] Remove deprecate-test-as-function deprecation. #13327

Merged
merged 1 commit into from
Apr 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 1 addition & 24 deletions packages/ember-debug/lib/handlers.js
Original file line number Diff line number Diff line change
@@ -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() { };

Expand All @@ -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];

Expand Down
18 changes: 1 addition & 17 deletions packages/ember-debug/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
});
Expand Down
3 changes: 0 additions & 3 deletions packages/ember-debug/lib/is-plain-function.js

This file was deleted.

75 changes: 10 additions & 65 deletions packages/ember-debug/tests/main_test.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
});