Skip to content
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
13 changes: 10 additions & 3 deletions packages/ember-debug/lib/deprecate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Logger from 'ember-console';

import { ENV } from 'ember-environment';

import { assert } from './index';
import { registerHandler as genericRegisterHandler, invoke } from './handlers';
/**
@module @ember/debug
Expand Down Expand Up @@ -159,7 +160,13 @@ if (DEBUG) {
@since 1.0.0
*/
deprecate = function deprecate(message, test, options) {
if (!options || (!options.id && !options.until)) {
if (ENV._ENABLE_DEPRECATION_OPTIONS_SUPPORT !== true) {
assert(missingOptionsDeprecation, options && (options.id || options.until));
assert(missingOptionsIdDeprecation, options.id);
assert(missingOptionsUntilDeprecation, options.until);
}

if ((!options || (!options.id && !options.until)) && ENV._ENABLE_DEPRECATION_OPTIONS_SUPPORT === true) {
deprecate(
missingOptionsDeprecation,
false,
Expand All @@ -171,7 +178,7 @@ if (DEBUG) {
);
}

if (options && !options.id) {
if (options && !options.id && ENV._ENABLE_DEPRECATION_OPTIONS_SUPPORT === true) {
deprecate(
missingOptionsIdDeprecation,
false,
Expand All @@ -183,7 +190,7 @@ if (DEBUG) {
);
}

if (options && !options.until) {
if (options && !options.until && ENV._ENABLE_DEPRECATION_OPTIONS_SUPPORT === true) {
deprecate(
missingOptionsUntilDeprecation,
options && options.until,
Expand Down
44 changes: 44 additions & 0 deletions packages/ember-debug/tests/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,25 @@ import {
let originalEnvValue;
let originalDeprecateHandler;
let originalWarnOptions;
let originalDeprecationOptions;

QUnit.module('ember-debug', {
setup() {
originalEnvValue = ENV.RAISE_ON_DEPRECATION;
originalDeprecateHandler = HANDLERS.deprecate;
originalWarnOptions = ENV._ENABLE_WARN_OPTIONS_SUPPORT;
originalDeprecationOptions = ENV._ENABLE_DEPRECATION_OPTIONS_SUPPORT;

ENV.RAISE_ON_DEPRECATION = true;
ENV._ENABLE_DEPRECATION_OPTIONS_SUPPORT = true;
},

teardown() {
HANDLERS.deprecate = originalDeprecateHandler;

ENV.RAISE_ON_DEPRECATION = originalEnvValue;
ENV._ENABLE_WARN_OPTIONS_SUPPORT = originalWarnOptions;
ENV._ENABLE_DEPRECATION_OPTIONS_SUPPORT = originalDeprecationOptions;
}
});

Expand Down Expand Up @@ -217,6 +221,24 @@ QUnit.test('Ember.deprecate without options triggers a deprecation', function(as
deprecate('foo', false, { });
});

QUnit.test('Ember.deprecate without options triggers an assertion', function(assert) {
expect(2);
ENV._ENABLE_DEPRECATION_OPTIONS_SUPPORT = false;

assert.throws(
() => deprecate('foo'),
new RegExp(missingOptionsDeprecation),
'proper assertion is triggered when options is missing'
);

assert.throws(
() => deprecate('foo', false, { }),
new RegExp(missingOptionsDeprecation),
'proper assertion is triggered when options is missing'
);
});


QUnit.test('Ember.deprecate without options.id triggers a deprecation', function(assert) {
assert.expect(2);

Expand All @@ -231,6 +253,17 @@ QUnit.test('Ember.deprecate without options.id triggers a deprecation', function
deprecate('foo', false, { until: 'forever' });
});

QUnit.test('Ember.deprecate without options.id triggers an assertion', function(assert) {
expect(1);
ENV._ENABLE_DEPRECATION_OPTIONS_SUPPORT = false;

assert.throws(
() => deprecate('foo', false, { until: 'forever' }),
new RegExp(missingOptionsIdDeprecation),
'proper assertion is triggered when options.id is missing'
);
});

QUnit.test('Ember.deprecate without options.until triggers a deprecation', function(assert) {
assert.expect(2);

Expand All @@ -245,6 +278,17 @@ QUnit.test('Ember.deprecate without options.until triggers a deprecation', funct
deprecate('foo', false, { id: 'test' });
});

QUnit.test('Ember.deprecate without options.until triggers an assertion', function(assert) {
expect(1);
ENV._ENABLE_DEPRECATION_OPTIONS_SUPPORT = false;

assert.throws(
() => deprecate('foo', false, { id: 'test' }),
new RegExp(missingOptionsUntilDeprecation),
'proper assertion is triggered when options.until is missing'
);
});

QUnit.test('warn without options triggers a deprecation', function(assert) {
assert.expect(2);

Expand Down