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
6 changes: 3 additions & 3 deletions packages/ember-debug/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ Ember.debug = function(message) {
@public
*/
Ember.deprecate = function(message, test, options) {
if (Ember.ENV.RAISE_ON_DEPRECATION) {
deprecationManager.setDefaultLevel(deprecationLevels.RAISE);
}
if (deprecationManager.getLevel(options && options.id) === deprecationLevels.SILENCE) {
return;
}
Expand Down Expand Up @@ -269,9 +272,6 @@ if (!Ember.testing) {
}
}

if (Ember.ENV.RAISE_ON_DEPRECATION) {
deprecationManager.setDefaultLevel(deprecationLevels.RAISE);
}
Ember.Debug = {
_addDeprecationLevel(id, level) {
deprecationManager.setLevel(id, level);
Expand Down
41 changes: 40 additions & 1 deletion packages/ember-debug/tests/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ QUnit.module('ember-debug', {
originalDeprecationDefault = deprecationManager.defaultLevel;
originalDeprecationLevels = deprecationManager.individualLevels;
originalEnvValue = Ember.ENV.RAISE_ON_DEPRECATION;
Ember.ENV.RAISE_ON_DEPRECATION = true;

Ember.ENV.RAISE_ON_DEPRECATION = false;
deprecationManager.setDefaultLevel(deprecationLevels.RAISE);
},

teardown() {
Expand All @@ -32,6 +34,43 @@ QUnit.test('Ember.deprecate does not throw if default level is silence', functio
}
});

QUnit.test('Ember.deprecate re-sets deprecation level to RAISE if ENV.RAISE_ON_DEPRECATION is set', function(assert) {
assert.expect(2);

deprecationManager.setDefaultLevel(deprecationLevels.SILENCE);

Ember.ENV.RAISE_ON_DEPRECATION = true;

assert.throws(function() {
Ember.deprecate('Should throw', false);
}, /Should throw/);

assert.equal(deprecationManager.defaultLevel, deprecationLevels.RAISE,
'default level re-set to RAISE');
});

QUnit.test('When ENV.RAISE_ON_DEPRECATION is true, it is still possible to silence a deprecation by id', function(assert) {
assert.expect(3);

Ember.ENV.RAISE_ON_DEPRECATION = true;
deprecationManager.setLevel('my-deprecation', deprecationLevels.SILENCE);

try {
Ember.deprecate('should be silenced with matching id', false, { id: 'my-deprecation' });
assert.ok(true, 'Did not throw when level is set by id');
} catch(e) {
assert.ok(false, `Expected Ember.deprecate not to throw but it did: ${e.message}`);
}

assert.throws(function() {
Ember.deprecate('Should throw with no id', false);
}, /Should throw with no id/);

assert.throws(function() {
Ember.deprecate('Should throw with non-matching id', false, { id: 'other-id' });
}, /Should throw with non-matching id/);
});

QUnit.test('Ember.deprecate throws deprecation if second argument is falsy', function() {
expect(3);

Expand Down