Skip to content

Commit

Permalink
Move expectDeprecation and expectNoDeprecation onto assert
Browse files Browse the repository at this point in the history
  • Loading branch information
thoov committed Jan 17, 2018
1 parent 74c9053 commit a4a65c3
Show file tree
Hide file tree
Showing 23 changed files with 210 additions and 181 deletions.
2 changes: 0 additions & 2 deletions .eslintrc-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ module.exports = {
},
globals: {
'expectAssertion': true,
'expectDeprecation': true,
'expectNoDeprecation': true,
'expectWarning': true,
'expectNoWarning': true,
'ignoreAssertion': true,
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ Within the Travis build, you can see that we (currently) run six different test

If your build is failing on the 'production' suite, you may be relying on a debug-only function that does not even exist in a production build (`Ember.warn`, `Ember.deprecate`, `Ember.assert`, etc.). These will pass on the 'each-package-tests' suite (and locally) because those functions are present in development builds.

There are helpers for many of these functions, which will resolve this for you: `expectDeprecation`, `expectAssertion`, etc. Please use these helpers when dealing with these functions.
There are helpers for many of these functions, which will resolve this for you: `assert.expectDeprecation`, `expectAssertion`, etc. Please use these helpers when dealing with these functions.

If your tests can't aren't covered a helper, one common solution is the use of `EmberDev.runningProdBuild`. Wrapping the debug-only dependent test in a check of this flag will cause that test to not be run in the prod test suite:
```javascript
Expand Down
2 changes: 1 addition & 1 deletion packages/container/tests/registry_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ moduleFor('Registry', class extends AbstractTestCase{

let registry;

expectDeprecation(() => {
assert.expectDeprecation(() => {
registry = new Registry({
resolver(fullName) {
return `${fullName}-resolved`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ moduleFor('Ember.Application Dependency Injection - Integration - default resolv
}, /Expected component:foo to resolve to an Ember\.Component but instead it was \.FooComponent\./);
}

[`@test no deprecation warning for component factories that extend from Ember.Component`]() {
expectNoDeprecation();
[`@test no deprecation warning for component factories that extend from Ember.Component`](assert) {
assert.expectNoDeprecation();
this.application.FooView = Component.extend();
this.privateRegistry.resolve('component:foo');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2757,7 +2757,7 @@ moduleFor('Components test: curly components', class extends RenderingTest {
})
});

expectDeprecation(() => {
assert.expectDeprecation(() => {
this.render('{{foo-bar}}');
}, /didInitAttrs called/);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ import { LinkComponent } from '../../utils/helpers';
import { classes as classMatcher } from '../../utils/test-helpers';

moduleFor('Link-to component', class extends ApplicationTest {
visitWithDeprecation(path, deprecation) {
let p;

expectDeprecation(() => {
p = this.visit(path);
}, deprecation);

return p;
}

['@test should be able to be inserted in DOM when the router is not present']() {
this.addTemplate('application', `{{#link-to 'index'}}Go to Index{{/link-to}}`);

Expand Down
4 changes: 2 additions & 2 deletions packages/ember-glimmer/tests/integration/content-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ class DynamicContentTest extends RenderingTest {
this.assertHTML('<p></p>');
}

['@test it can render a capitalized path with no deprecation']() {
expectNoDeprecation();
['@test it can render a capitalized path with no deprecation'](assert) {
assert.expectNoDeprecation();

this.renderPath('CaptializedPath', { CaptializedPath: 'no deprecation' });

Expand Down
62 changes: 31 additions & 31 deletions packages/ember-glimmer/tests/integration/helpers/render-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,51 @@ moduleFor('Helpers test: {{render}}', class extends RenderingTest {
ENV._ENABLE_RENDER_SUPPORT = this.originalRenderSupport;
}

['@test should render given template']() {
['@test should render given template'](assert) {
this.registerTemplate('home', '<p>BYE</p>');

expectDeprecation(() => {
assert.expectDeprecation(() => {
this.render(`<h1>HI</h1>{{render 'home'}}`);
}, /Please refactor [\w\{\}"` ]+ to a component/);

this.assertText('HIBYE');
}

['@test uses `controller:basic` as the basis for a generated controller when none exists for specified name']() {
['@test uses `controller:basic` as the basis for a generated controller when none exists for specified name'](assert) {
this.owner.register('controller:basic', Controller.extend({
isBasicController: true
}));
this.registerTemplate('home', '{{isBasicController}}');

expectDeprecation(() => {
assert.expectDeprecation(() => {
this.render(`{{render 'home'}}`);
}, /Please refactor [\w\{\}"` ]+ to a component/);

this.assertText('true');
}

['@test generates a controller if none exists']() {
['@test generates a controller if none exists'](assert) {
this.registerTemplate('home', '<p>{{this}}</p>');

expectDeprecation(() => {
assert.expectDeprecation(() => {
this.render(`<h1>HI</h1>{{render 'home'}}`);
}, /Please refactor [\w\{\}"` ]+ to a component/);

this.assertText('HI(generated home controller)');
}

['@test should use controller with the same name as template if present']() {
['@test should use controller with the same name as template if present'](assert) {
this.owner.register('controller:home', Controller.extend({ name: 'home' }));
this.registerTemplate('home', '{{name}}<p>BYE</p>');

expectDeprecation(() => {
assert.expectDeprecation(() => {
this.render(`<h1>HI</h1>{{render 'home'}}`);
}, /Please refactor [\w\{\}"` ]+ to a component/);

this.assertText('HIhomeBYE');
}

['@test should render nested helpers']() {
['@test should render nested helpers'](assert) {
this.owner.register('controller:home', Controller.extend());
this.owner.register('controller:foo', Controller.extend());
this.owner.register('controller:bar', Controller.extend());
Expand All @@ -68,7 +68,7 @@ moduleFor('Helpers test: {{render}}', class extends RenderingTest {
this.registerTemplate('home', '<p>BYE</p>');
this.registerTemplate('baz', `<p>BAZ</p>`);

expectDeprecation(() => {
assert.expectDeprecation(() => {
this.registerTemplate('foo', `<p>FOO</p>{{render 'bar'}}`);
this.registerTemplate('bar', `<p>BAR</p>{{render 'baz'}}`);
this.render('<h1>HI</h1>{{render \'foo\'}}');
Expand All @@ -77,25 +77,25 @@ moduleFor('Helpers test: {{render}}', class extends RenderingTest {
this.assertText('HIFOOBARBAZ');
}

['@test should have assertion if the template does not exist']() {
['@test should have assertion if the template does not exist'](assert) {
this.owner.register('controller:oops', Controller.extend());

expectDeprecation(() => {
assert.expectDeprecation(() => {
expectAssertion(() => {
this.render(`<h1>HI</h1>{{render 'oops'}}`);
}, 'You used `{{render \'oops\'}}`, but \'oops\' can not be found as a template.');
}, /Please refactor [\w\{\}"` ]+ to a component/);
}

['@test should render given template with the singleton controller as its context']() {
['@test should render given template with the singleton controller as its context'](assert) {
this.owner.register('controller:post', Controller.extend({
init() {
this.set('title', `It's Simple Made Easy`);
}
}));
this.registerTemplate('post', '<p>{{title}}</p>');

expectDeprecation(() => {
assert.expectDeprecation(() => {
this.render(`<h1>HI</h1>{{render 'post'}}`);
}, /Please refactor [\w\{\}"` ]+ to a component/);

Expand Down Expand Up @@ -132,7 +132,7 @@ moduleFor('Helpers test: {{render}}', class extends RenderingTest {

this.registerTemplate('post', '<p>{{title}}</p>');

expectDeprecation(() => {
assert.expectDeprecation(() => {
this.render(`{{#if showPost}}{{render 'post'}}{{else}}Nothing here{{/if}}`, { showPost: false });
}, /Please refactor [\w\{\}"` ]+ to a component/);

Expand All @@ -159,11 +159,11 @@ moduleFor('Helpers test: {{render}}', class extends RenderingTest {
assert.strictEqual(willDestroyFired, 0, 'it did not destroy the controller');
}

['@test should render given template with a supplied model']() {
['@test should render given template with a supplied model'](assert) {
this.owner.register('controller:post', Controller.extend());
this.registerTemplate('post', '<p>{{model.title}}</p>');

expectDeprecation(() => {
assert.expectDeprecation(() => {
this.render(`<h1>HI</h1>{{render 'post' post}}`, {
post: {
title: `It's Simple Made Easy`
Expand Down Expand Up @@ -198,7 +198,7 @@ moduleFor('Helpers test: {{render}}', class extends RenderingTest {

this.registerTemplate('post', '<p>{{model.title}}</p>');

expectDeprecation(() => {
assert.expectDeprecation(() => {
this.render(`{{#if showPost}}{{render 'post' post}}{{else}}Nothing here{{/if}}`, {
showPost: false,
post: {
Expand Down Expand Up @@ -247,7 +247,7 @@ moduleFor('Helpers test: {{render}}', class extends RenderingTest {
this.registerTemplate('post', '<p>{{model.title}}</p>');

let postDidChange = 0;
expectDeprecation(() => {
assert.expectDeprecation(() => {
this.render(`<h1>HI</h1>{{render 'post' post}}`, {
postDidChange: observer('post', function() {
postDidChange++;
Expand All @@ -266,11 +266,11 @@ moduleFor('Helpers test: {{render}}', class extends RenderingTest {
assert.equal(postDidChange, 0);
}

['@test should raise an error when a given controller name does not resolve to a controller']() {
['@test should raise an error when a given controller name does not resolve to a controller'](assert) {
this.registerTemplate('home', '<p>BYE</p>');
this.owner.register('controller:posts', Controller.extend());

expectDeprecation(() => {
assert.expectDeprecation(() => {
expectAssertion(() => {
this.render(`<h1>HI</h1>{{render "home" controller="postss"}}`);
}, /The controller name you supplied \'postss\' did not resolve to a controller./);
Expand All @@ -291,7 +291,7 @@ moduleFor('Helpers test: {{render}}', class extends RenderingTest {
}
}));

expectDeprecation(() => {
assert.expectDeprecation(() => {
this.render('{{render "home" controller="posts"}}');
}, /Please refactor [\w\{\}"` ]+ to a component/);

Expand All @@ -310,11 +310,11 @@ moduleFor('Helpers test: {{render}}', class extends RenderingTest {
this.assertText('0');
}

['@test should render templates with models multiple times']() {
['@test should render templates with models multiple times'](assert) {
this.owner.register('controller:post', Controller.extend());

this.registerTemplate('post', '<p>{{model.title}}</p>');
expectDeprecation(() => {
assert.expectDeprecation(() => {
this.render(`<h1>HI</h1> {{render 'post' post1}} {{render 'post' post2}}`, {
post1: {
title: 'Me First'
Expand Down Expand Up @@ -344,7 +344,7 @@ moduleFor('Helpers test: {{render}}', class extends RenderingTest {
this.registerTemplate('post', '<p>{{#unless model.zero}}NOTHING{{/unless}}</p>');
this.owner.register('controller:post', Controller.extend());

expectDeprecation(() => {
assert.expectDeprecation(() => {
this.render(`<h1>HI</h1> {{render 'post' zero}} {{render 'post' nonexistent}}`, {
model: {
zero: false
Expand All @@ -362,7 +362,7 @@ moduleFor('Helpers test: {{render}}', class extends RenderingTest {
let post = {
title: 'Rails is omakase'
};
expectDeprecation(() => {
assert.expectDeprecation(() => {
this.render(`<h1>HI</h1> {{render 'post'}} {{render 'post' post}}`, {
post
});
Expand All @@ -383,7 +383,7 @@ moduleFor('Helpers test: {{render}}', class extends RenderingTest {
assert.ok(this.$().text().match(/^HI ?Title: ?Title:Rails is omakase$/));
}

['@test works with dot notation']() {
['@test works with dot notation'](assert) {
this.registerTemplate('blog.post', '{{uniqueId}}');

let id = 0;
Expand All @@ -394,7 +394,7 @@ moduleFor('Helpers test: {{render}}', class extends RenderingTest {
}
}));

expectDeprecation(() => {
assert.expectDeprecation(() => {
this.render('{{render "blog.post"}}');
}, /Please refactor [\w\.{\}"` ]+ to a component/);

Expand Down Expand Up @@ -439,14 +439,14 @@ moduleFor('Helpers test: {{render}}', class extends RenderingTest {

this.owner.register('router:main', routerStub, { instantiate: false });

expectDeprecation(() => {
assert.expectDeprecation(() => {
this.render(`{{render 'post' post1}}`);
}, /Please refactor [\w\{\}"` ]+ to a component/);

postController.send('someAction');
}

['@test render helper emits useful backtracking re-render assertion message']() {
['@test render helper emits useful backtracking re-render assertion message'](assert) {
this.owner.register('controller:outer', Controller.extend());
this.owner.register('controller:inner', Controller.extend({
propertyWithError: computed(function() {
Expand All @@ -457,7 +457,7 @@ moduleFor('Helpers test: {{render}}', class extends RenderingTest {

let expectedBacktrackingMessage = /modified "model\.name" twice on \[object Object\] in a single render\. It was rendered in "controller:outer \(with the render helper\)" and modified in "controller:inner \(with the render helper\)"/;

expectDeprecation(() => {
assert.expectDeprecation(() => {
let person = { name: 'Ben' };

this.registerTemplate('outer', `Hi {{model.name}} | {{render 'inner' model}}`);
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-metal/tests/map_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function testMap(nameAndFunc) {
});

QUnit.test('delete', function(assert) {
expectNoDeprecation();
assert.expectNoDeprecation();

map.set(object, 'winning');
map.set(number, 'winning');
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-metal/tests/mixin/required_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ let PartialMixin, FinalMixin, obj;
let originalEnvVal;

moduleFor('Module.required', class extends AbstractTestCase {
beforeEach() {
beforeEach(assert) {
originalEnvVal = ENV._ENABLE_PROPERTY_REQUIRED_SUPPORT;
ENV._ENABLE_PROPERTY_REQUIRED_SUPPORT = true;
expectDeprecation(() => {
assert.expectDeprecation(() => {
PartialMixin = Mixin.create({
foo: required(),
bar: 'BAR'
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-metal/tests/properties_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ moduleFor('Ember.deprecateProperty', class extends AbstractTestCase {

deprecateProperty(obj, 'baz', 'foo');

expectDeprecation();
assert.expectDeprecation();
assert.equal(obj.baz, obj.foo, 'baz and foo are equal');

obj.foo = 'blammo';
Expand All @@ -95,7 +95,7 @@ moduleFor('Ember.deprecateProperty', class extends AbstractTestCase {

deprecateProperty(obj, 'baz', 'foo');

expectDeprecation();
assert.expectDeprecation();
obj.baz = 'bloop';
assert.equal(obj.foo, 'bloop', 'updating baz updates foo');
assert.equal(obj.baz, obj.foo, 'baz and foo are equal');
Expand Down
14 changes: 7 additions & 7 deletions packages/ember-runtime/tests/computed/computed_macros_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,31 +465,31 @@ testBoth('computed.deprecatingAlias', function(get, set, assert) {
defineProperty(obj, 'quzAlias', deprecatingAlias('quz'));
defineProperty(obj, 'bayAlias', deprecatingAlias('bay'));

expectDeprecation(function() {
assert.expectDeprecation(function() {
assert.equal(get(obj, 'barAlias'), 'asdf');
}, 'Usage of `barAlias` is deprecated, use `bar` instead.');

expectDeprecation(function() {
assert.expectDeprecation(function() {
assert.equal(get(obj, 'bazAlias'), null);
}, 'Usage of `bazAlias` is deprecated, use `baz` instead.');

expectDeprecation(function() {
assert.expectDeprecation(function() {
assert.equal(get(obj, 'quzAlias'), false);
}, 'Usage of `quzAlias` is deprecated, use `quz` instead.');

expectDeprecation(function() {
assert.expectDeprecation(function() {
assert.equal(get(obj, 'bayAlias'), 'apple');
}, 'Usage of `bayAlias` is deprecated, use `bay` instead.');

expectDeprecation(function() {
assert.expectDeprecation(function() {
set(obj, 'barAlias', 'newBar');
}, 'Usage of `barAlias` is deprecated, use `bar` instead.');

expectDeprecation(function() {
assert.expectDeprecation(function() {
set(obj, 'bazAlias', 'newBaz');
}, 'Usage of `bazAlias` is deprecated, use `baz` instead.');

expectDeprecation(function() {
assert.expectDeprecation(function() {
set(obj, 'quzAlias', null);
}, 'Usage of `quzAlias` is deprecated, use `quz` instead.');

Expand Down
Loading

0 comments on commit a4a65c3

Please sign in to comment.