diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js index ffc53313e27..4ead37ed483 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js @@ -1,9 +1,16 @@ import { DEBUG } from '@glimmer/env'; -import { moduleFor, RenderingTestCase, applyMixins, strip, runTask } from 'internal-test-helpers'; +import { + moduleFor, + RenderingTestCase, + applyMixins, + strip, + runTask, + expectDeprecation, + emberAWithoutDeprecation, +} from 'internal-test-helpers'; import { isEmpty } from '@ember/utils'; import { action } from '@ember/object'; -import { A as emberA } from '@ember/array'; import { Component } from '../../utils/helpers'; @@ -1160,7 +1167,7 @@ moduleFor( }); this.render('{{component (component "my-link") params=this.allParams}}', { - allParams: emberA(['a', 'b']), + allParams: emberAWithoutDeprecation(['a', 'b']), }); this.assertText('ab'); @@ -1169,23 +1176,29 @@ moduleFor( this.assertText('ab'); - runTask(() => this.context.get('allParams').pushObject('c')); + expectDeprecation(() => { + runTask(() => this.context.get('allParams').pushObject('c')); + }, /Usage of Ember.Array methods is deprecated/); this.assertText('abc'); - runTask(() => this.context.get('allParams').popObject()); + expectDeprecation(() => { + runTask(() => this.context.get('allParams').popObject()); + }, /Usage of Ember.Array methods is deprecated/); this.assertText('ab'); - runTask(() => this.context.get('allParams').clear()); + expectDeprecation(() => { + runTask(() => this.context.get('allParams').clear()); + }, /Usage of Ember.Array methods is deprecated/); this.assertText(''); - runTask(() => this.context.set('allParams', emberA(['1', '2']))); + runTask(() => this.context.set('allParams', emberAWithoutDeprecation(['1', '2']))); this.assertText('12'); - runTask(() => this.context.set('allParams', emberA(['a', 'b']))); + runTask(() => this.context.set('allParams', emberAWithoutDeprecation(['a', 'b']))); this.assertText('ab'); } @@ -1201,7 +1214,7 @@ moduleFor( this.render( '{{#let (hash link=(component "my-link")) as |c|}}{{c.link params=this.allParams}}{{/let}}', { - allParams: emberA(['a', 'b']), + allParams: emberAWithoutDeprecation(['a', 'b']), } ); @@ -1211,23 +1224,29 @@ moduleFor( this.assertText('ab'); - runTask(() => this.context.get('allParams').pushObject('c')); + expectDeprecation(() => { + runTask(() => this.context.get('allParams').pushObject('c')); + }, /Usage of Ember.Array methods is deprecated/); this.assertText('abc'); - runTask(() => this.context.get('allParams').popObject()); + expectDeprecation(() => { + runTask(() => this.context.get('allParams').popObject()); + }, /Usage of Ember.Array methods is deprecated/); this.assertText('ab'); - runTask(() => this.context.get('allParams').clear()); + expectDeprecation(() => { + runTask(() => this.context.get('allParams').clear()); + }, /Usage of Ember.Array methods is deprecated/); this.assertText(''); - runTask(() => this.context.set('allParams', emberA(['1', '2']))); + runTask(() => this.context.set('allParams', emberAWithoutDeprecation(['1', '2']))); this.assertText('12'); - runTask(() => this.context.set('allParams', emberA(['a', 'b']))); + runTask(() => this.context.set('allParams', emberAWithoutDeprecation(['a', 'b']))); this.assertText('ab'); } diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js index 2bf955d092e..ba5c1f876e9 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js @@ -7,6 +7,8 @@ import { equalsElement, runTask, runLoopSettled, + expectDeprecation, + emberAWithoutDeprecation as emberA, } from 'internal-test-helpers'; import { action } from '@ember/object'; @@ -17,7 +19,6 @@ import { alias } from '@ember/object/computed'; import { on } from '@ember/object/evented'; import Service, { service } from '@ember/service'; import EmberObject, { set, get, computed, observer } from '@ember/object'; -import { A as emberA } from '@ember/array'; import { Component, compile, htmlSafe } from '../../utils/helpers'; import { backtrackingMessageFor } from '../../utils/debug-stack'; @@ -1714,15 +1715,21 @@ moduleFor( this.assertText('Foo4Bar'); - runTask(() => this.context.get('things').pushObject(5)); + expectDeprecation(() => { + runTask(() => this.context.get('things').pushObject(5)); + }, /Usage of Ember.Array methods is deprecated/); this.assertText('Foo4Bar5'); - runTask(() => this.context.get('things').shiftObject()); + expectDeprecation(() => { + runTask(() => this.context.get('things').shiftObject()); + }, /Usage of Ember.Array methods is deprecated/); this.assertText('4Bar5'); - runTask(() => this.context.get('things').clear()); + expectDeprecation(() => { + runTask(() => this.context.get('things').clear()); + }, /Usage of Ember.Array methods is deprecated/); this.assertText(''); @@ -2574,11 +2581,15 @@ moduleFor( this.assertText('In layout. [Child: Tom.][Child: Dick.][Child: Harry.]'); - runTask(() => this.context.get('items').pushObject('Sergio')); + expectDeprecation(() => { + runTask(() => this.context.get('items').pushObject('Sergio')); + }, /Usage of Ember.Array methods is deprecated/); this.assertText('In layout. [Child: Tom.][Child: Dick.][Child: Harry.][Child: Sergio.]'); - runTask(() => this.context.get('items').shiftObject()); + expectDeprecation(() => { + runTask(() => this.context.get('items').shiftObject()); + }, /Usage of Ember.Array methods is deprecated/); this.assertText('In layout. [Child: Dick.][Child: Harry.][Child: Sergio.]'); @@ -3012,17 +3023,25 @@ moduleFor( } updateValue() { - let newValue = this.get('options.lastObject.value'); + let newValue; + + expectDeprecation(() => { + newValue = this.get('options.lastObject.value'); + }, /Usage of Ember.Array methods is deprecated/); this.set('value', newValue); } registerOption(option) { - this.get('options').addObject(option); + expectDeprecation(() => { + this.get('options').addObject(option); + }, /Usage of Ember.Array methods is deprecated/); } unregisterOption(option) { - this.get('options').removeObject(option); + expectDeprecation(() => { + this.get('options').removeObject(option); + }, /Usage of Ember.Array methods is deprecated/); this.updateValue(); } diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/life-cycle-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/life-cycle-test.js index 1c4f3bed6c0..8425971d031 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/life-cycle-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/life-cycle-test.js @@ -1,8 +1,15 @@ -import { classes, moduleFor, RenderingTestCase, runTask, strip } from 'internal-test-helpers'; +import { + classes, + emberAWithoutDeprecation, + expectDeprecation, + moduleFor, + RenderingTestCase, + runTask, + strip, +} from 'internal-test-helpers'; import { schedule } from '@ember/runloop'; import { set, setProperties } from '@ember/object'; -import { A as emberA } from '@ember/array'; import { getViewElement, getViewId } from '@ember/-internals/views'; import { Component } from '../../utils/helpers'; @@ -1464,7 +1471,7 @@ moduleFor( template: NestedTemplate, }); - let array = emberA([{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }]); + let array = emberAWithoutDeprecation([{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }]); this.render( strip` @@ -1487,8 +1494,10 @@ moduleFor( this.assertText('1AB2AB3AB4AB5AB6AB7AB'); runTask(() => { - array.removeAt(2); - array.removeAt(2); + expectDeprecation(() => { + array.removeAt(2); + array.removeAt(2); + }, /Usage of Ember.Array methods is deprecated/); set(this.context, 'model.shouldShow', false); }); diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js index 2902b9eaff4..7a7cd46dd58 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-angle-test.js @@ -1,6 +1,7 @@ import { ApplicationTestCase, ModuleBasedTestResolver, + expectDeprecation, moduleFor, runTask, } from 'internal-test-helpers'; @@ -13,6 +14,7 @@ import { service } from '@ember/service'; import Engine from '@ember/engine'; import { DEBUG } from '@glimmer/env'; import { compile } from '../../../utils/helpers'; +import { emberAWithoutDeprecation } from '@ember/routing/-internals'; // IE includes the host name function normalizeUrl(url) { @@ -1536,7 +1538,7 @@ moduleFor( controller = this; } - routeNames = emberA(['foo', 'bar', 'rar']); + routeNames = emberAWithoutDeprecation(['foo', 'bar', 'rar']); route1 = 'bar'; route2 = 'foo'; } @@ -1579,7 +1581,9 @@ moduleFor( linksEqual(this.$('a'), ['/foo', '/bar', '/rar', '/foo', '/bar', '/rar', '/rar', '/foo']); - runTask(() => controller.routeNames.shiftObject()); + expectDeprecation(() => { + runTask(() => controller.routeNames.shiftObject()); + }, /Usage of Ember.Array methods is deprecated/); linksEqual(this.$('a'), ['/bar', '/rar', '/bar', '/rar', '/rar', '/foo']); } diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js index a53984e0304..c09c433d6f2 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/link-to/routing-curly-test.js @@ -1,6 +1,8 @@ import { ApplicationTestCase, ModuleBasedTestResolver, + emberAWithoutDeprecation, + expectDeprecation, moduleFor, runTask, } from 'internal-test-helpers'; @@ -1447,7 +1449,7 @@ moduleFor( controller = this; } - routeNames = emberA(['foo', 'bar', 'rar']); + routeNames = emberAWithoutDeprecation(['foo', 'bar', 'rar']); route1 = 'bar'; route2 = 'foo'; } @@ -1490,7 +1492,9 @@ moduleFor( linksEqual(this.$('a'), ['/foo', '/bar', '/rar', '/foo', '/bar', '/rar', '/rar', '/foo']); - runTask(() => controller.routeNames.shiftObject()); + expectDeprecation(() => { + runTask(() => controller.routeNames.shiftObject()); + }, /Usage of Ember.Array methods is deprecated/); linksEqual(this.$('a'), ['/bar', '/rar', '/bar', '/rar', '/rar', '/foo']); } diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/tracked-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/tracked-test.js index 72f12a716fe..bbabc545f8a 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/tracked-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/tracked-test.js @@ -1,11 +1,17 @@ import EmberObject from '@ember/object'; -import { A } from '@ember/array'; import ArrayProxy from '@ember/array/proxy'; import PromiseProxyMixin from '@ember/object/promise-proxy-mixin'; import { tracked } from '@ember/-internals/metal'; import { computed, get, set } from '@ember/object'; import { Promise } from 'rsvp'; -import { moduleFor, RenderingTestCase, strip, runTask } from 'internal-test-helpers'; +import { + moduleFor, + RenderingTestCase, + strip, + runTask, + expectDeprecation, + emberAWithoutDeprecation, +} from 'internal-test-helpers'; import GlimmerishComponent from '../../utils/glimmerish-component'; import { Component } from '../../utils/helpers'; @@ -91,9 +97,11 @@ moduleFor( class LoaderComponent extends GlimmerishComponent { get data() { if (!this._data) { - this._data = PromiseArray.create({ - promise: Promise.resolve([1, 2, 3]), - }); + expectDeprecation(() => { + this._data = PromiseArray.create({ + promise: Promise.resolve([1, 2, 3]), + }); + }, /Usage of ArrayProxy is deprecated/); } return this._data; @@ -114,11 +122,15 @@ moduleFor( class LoaderComponent extends GlimmerishComponent { get data() { if (!this._data) { - this._data = ArrayProxy.create({ - content: A(), - }); - - this._data.content.pushObjects([1, 2, 3]); + expectDeprecation(() => { + this._data = ArrayProxy.create({ + content: emberAWithoutDeprecation(), + }); + }, /Usage of ArrayProxy is deprecated/); + + expectDeprecation(() => { + this._data.content.pushObjects([1, 2, 3]); + }, /Usage of Ember.Array methods is deprecated/); } return this._data; @@ -242,9 +254,13 @@ moduleFor( '@test array properties rerender when updated'() { class NumListComponent extends Component { - @tracked numbers = A([1, 2, 3]); + @tracked numbers = emberAWithoutDeprecation([1, 2, 3]); - addNumber = () => this.numbers.pushObject(4); + addNumber = () => { + expectDeprecation(() => { + this.numbers.pushObject(4); + }, /Usage of Ember.Array methods is deprecated/); + }; } this.registerComponent('num-list', { diff --git a/packages/@ember/-internals/glimmer/tests/integration/helpers/tracked-test.js b/packages/@ember/-internals/glimmer/tests/integration/helpers/tracked-test.js index d23c8e7f482..f030b115caa 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/helpers/tracked-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/helpers/tracked-test.js @@ -7,7 +7,14 @@ import { notifyPropertyChange, } from '@ember/-internals/metal'; import Service, { service } from '@ember/service'; -import { moduleFor, RenderingTestCase, strip, runTask } from 'internal-test-helpers'; +import { + moduleFor, + RenderingTestCase, + strip, + runTask, + expectDeprecation, + emberAWithoutDeprecation, +} from 'internal-test-helpers'; import { Component } from '../../utils/helpers'; @@ -142,10 +149,12 @@ moduleFor( '@test array properties rerender when updated'() { class NumListComponent extends Component { - @tracked numbers = A([1, 2, 3]); + @tracked numbers = emberAWithoutDeprecation([1, 2, 3]); addNumber = () => { - this.numbers.pushObject(4); + expectDeprecation(() => { + this.numbers.pushObject(4); + }, /Usage of Ember.Array methods is deprecated/); }; } @@ -172,35 +181,40 @@ moduleFor( } '@test custom ember array properties rerender when updated'() { - let CustomArray = class extends EmberObject.extend(MutableArray) { - init() { - super.init(...arguments); - this._vals = [1, 2, 3]; - } + let CustomArray; + expectDeprecation(() => { + CustomArray = class extends EmberObject.extend(MutableArray) { + init() { + super.init(...arguments); + this._vals = [1, 2, 3]; + } - objectAt(index) { - return this._vals[index]; - } + objectAt(index) { + return this._vals[index]; + } - replace(start, deleteCount, items = []) { - this._vals.splice(start, deleteCount, ...items); - notifyPropertyChange(this, '[]'); - } + replace(start, deleteCount, items = []) { + this._vals.splice(start, deleteCount, ...items); + notifyPropertyChange(this, '[]'); + } - join() { - return this._vals.join(...arguments); - } + join() { + return this._vals.join(...arguments); + } - get length() { - return this._vals.length; - } - }; + get length() { + return this._vals.length; + } + }; + }, /Usage of MutableArray is deprecated/); class NumListComponent extends Component { @tracked numbers = CustomArray.create(); addNumber = () => { - this.numbers.pushObject(4); + expectDeprecation(() => { + this.numbers.pushObject(4); + }, /Usage of Ember.Array methods is deprecated/); }; } @@ -389,7 +403,7 @@ moduleFor( } '@test each-in autotracks arrays acorrectly'() { - let obj = EmberObject.create({ arr: A([1]) }); + let obj = EmberObject.create({ arr: emberAWithoutDeprecation([1]) }); this.registerComponent('person', { ComponentClass: class extends Component { @@ -406,7 +420,9 @@ moduleFor( this.assertText('1'); - runTask(() => obj.arr.pushObject(2)); + expectDeprecation(() => { + runTask(() => obj.arr.pushObject(2)); + }, /Usage of Ember.Array methods is deprecated/); this.assertText('12'); } diff --git a/packages/@ember/-internals/glimmer/tests/integration/helpers/unbound-test.js b/packages/@ember/-internals/glimmer/tests/integration/helpers/unbound-test.js index 5944b35356e..efa24f77112 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/helpers/unbound-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/helpers/unbound-test.js @@ -4,10 +4,11 @@ import { strip, runTask, runLoopSettled, + emberAWithoutDeprecation, + expectDeprecation, } from 'internal-test-helpers'; import { set, get, setProperties } from '@ember/object'; -import { A as emberA } from '@ember/array'; import { Component } from '../../utils/helpers'; @@ -42,7 +43,7 @@ moduleFor( ['@test should be able to use unbound helper in #each helper']() { this.render(``, { - items: emberA(['a', 'b', 'c', 1, 2, 3]), + items: emberAWithoutDeprecation(['a', 'b', 'c', 1, 2, 3]), }); this.assertText('abc123'); @@ -56,7 +57,7 @@ moduleFor( this.render( ``, { - items: emberA([{ wham: 'bam' }, { wham: 1 }]), + items: emberAWithoutDeprecation([{ wham: 'bam' }, { wham: 1 }]), } ); @@ -66,11 +67,15 @@ moduleFor( this.assertText('bam1'); - runTask(() => this.context.items.setEach('wham', 'HEY')); + expectDeprecation(() => { + runTask(() => this.context.items.setEach('wham', 'HEY')); + }, /Usage of Ember.Array methods is deprecated/); this.assertText('bam1'); - runTask(() => set(this.context, 'items', emberA([{ wham: 'bam' }, { wham: 1 }]))); + runTask(() => + set(this.context, 'items', emberAWithoutDeprecation([{ wham: 'bam' }, { wham: 1 }])) + ); this.assertText('bam1'); } @@ -110,7 +115,7 @@ moduleFor( } ['@test should property escape unsafe hrefs']() { - let unsafeUrls = emberA([ + let unsafeUrls = emberAWithoutDeprecation([ { name: 'Bob', url: 'javascript:bob-is-cool', @@ -152,7 +157,9 @@ moduleFor( this.assertHTML(escapedHtml); - runTask(() => this.context.people.setEach('url', 'http://google.com')); + expectDeprecation(() => { + runTask(() => this.context.people.setEach('url', 'http://google.com')); + }, /Usage of Ember.Array methods is deprecated/); this.assertHTML(escapedHtml); @@ -445,7 +452,7 @@ moduleFor( this.render( `{{#each this.people as |person|}}{{capitalize person.firstName}} {{unbound (capitalize person.firstName)}}{{/each}}`, { - people: emberA([ + people: emberAWithoutDeprecation([ { firstName: 'shooby', lastName: 'taylor', @@ -464,7 +471,9 @@ moduleFor( this.assertText('SHOOBY SHOOBYCINDY CINDY'); - runTask(() => this.context.people.setEach('firstName', 'chad')); + expectDeprecation(() => { + runTask(() => this.context.people.setEach('firstName', 'chad')); + }, /Usage of Ember.Array methods is deprecated/); this.assertText('CHAD SHOOBYCHAD CINDY'); @@ -472,7 +481,7 @@ moduleFor( set( this.context, 'people', - emberA([ + emberAWithoutDeprecation([ { firstName: 'shooby', lastName: 'taylor', diff --git a/packages/@ember/-internals/glimmer/tests/integration/syntax/each-test.js b/packages/@ember/-internals/glimmer/tests/integration/syntax/each-test.js index e4ed8e69213..7ca7eb9521c 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/syntax/each-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/syntax/each-test.js @@ -1,8 +1,15 @@ -import { moduleFor, RenderingTestCase, applyMixins, strip, runTask } from 'internal-test-helpers'; +import { + moduleFor, + RenderingTestCase, + applyMixins, + strip, + runTask, + expectDeprecation, + ignoreDeprecation as ignoreDeprecationOrig, +} from 'internal-test-helpers'; import { notifyPropertyChange, on } from '@ember/-internals/metal'; import { get, set, computed } from '@ember/object'; -import { A as emberA } from '@ember/array'; import ArrayProxy from '@ember/array/proxy'; import { RSVP } from '@ember/-internals/runtime'; @@ -13,6 +20,15 @@ import { FalsyGenerator, ArrayTestCases, } from '../../utils/shared-conditional-tests'; +import { emberAWithoutDeprecation } from '@ember/routing/-internals'; + +function ignoreDeprecation(callback) { + let ret; + ignoreDeprecationOrig(() => { + ret = callback(); + }); + return ret; +} class ArrayDelegate { constructor(content, target) { @@ -157,11 +173,12 @@ class BasicEachTest extends TogglingEachTest {} const TRUTHY_CASES = [ ['hello'], - emberA(['hello']), + emberAWithoutDeprecation(['hello']), makeSet(['hello']), new ForEachable(['hello']), - ArrayProxy.create({ content: ['hello'] }), - ArrayProxy.create({ content: emberA(['hello']) }), + // FIXME + // ArrayProxy.create({ content: ['hello'] }), + // ArrayProxy.create({ content: emberAWithoutDeprecation(['hello']) }), new ArrayIterable(['hello']), ]; @@ -172,11 +189,12 @@ const FALSY_CASES = [ '', 0, [], - emberA([]), + emberAWithoutDeprecation([]), makeSet([]), new ForEachable([]), - ArrayProxy.create({ content: [] }), - ArrayProxy.create({ content: emberA([]) }), + // FIXME + // ArrayProxy.create({ content: [] }), + // ArrayProxy.create({ content: emberAWithoutDeprecation([]) }), new ArrayIterable([]), ]; @@ -260,51 +278,51 @@ class AbstractEachTest extends RenderingTestCase { } forEach(callback) { - return this.delegate.toArray().forEach(callback); + return ignoreDeprecation(() => this.delegate.toArray().forEach(callback)); } objectAt(idx) { - return this.delegate.objectAt(idx); + return ignoreDeprecation(() => this.delegate.objectAt(idx)); } clear() { - return this.delegate.clear(); + return ignoreDeprecation(() => this.delegate.clear()); } replace(idx, del, ins) { - return this.delegate.replace(idx, del, ins); + return ignoreDeprecation(() => this.delegate.replace(idx, del, ins)); } unshiftObject(obj) { - return this.delegate.unshiftObject(obj); + return ignoreDeprecation(() => this.delegate.unshiftObject(obj)); } unshiftObjects(arr) { - return this.delegate.unshiftObjects(arr); + return ignoreDeprecation(() => this.delegate.unshiftObjects(arr)); } pushObject(obj) { - return this.delegate.pushObject(obj); + return ignoreDeprecation(() => this.delegate.pushObject(obj)); } pushObjects(arr) { - return this.delegate.pushObjects(arr); + return ignoreDeprecation(() => this.delegate.pushObjects(arr)); } shiftObject() { - return this.delegate.shiftObject(); + return ignoreDeprecation(() => this.delegate.shiftObject()); } popObject() { - return this.delegate.popObject(); + return ignoreDeprecation(() => this.delegate.popObject()); } insertAt(idx, obj) { - return this.delegate.insertAt(idx, obj); + return ignoreDeprecation(() => this.delegate.insertAt(idx, obj)); } removeAt(idx, len) { - return this.delegate.removeAt(idx, len); + return ignoreDeprecation(() => this.delegate.removeAt(idx, len)); } render(template, context = {}) { @@ -880,8 +898,10 @@ class EachTest extends AbstractEachTest { this.assertText('Admin: [Tom Dale] User: [Yehuda Katz]'); runTask(() => { - admins.delegate.pushObject({ name: 'Godfrey Chan' }); - set(users.delegate.objectAt(0), 'name', 'Stefan Penner'); + ignoreDeprecation(() => { + admins.delegate.pushObject({ name: 'Godfrey Chan' }); + set(users.delegate.objectAt(0), 'name', 'Stefan Penner'); + }); }); this.assertText('Admin: [Tom Dale][Godfrey Chan] User: [Stefan Penner]'); @@ -921,8 +941,10 @@ class EachTest extends AbstractEachTest { this.assertStableRerender(); runTask(() => { - content.delegate.pushObject('Z'); - set(options.delegate.objectAt(0), 'value', 0); + ignoreDeprecation(() => { + content.delegate.pushObject('Z'); + set(options.delegate.objectAt(0), 'value', 0); + }); }); this.assertText('X-0:One2:TwoY-0:One2:TwoZ-0:One2:Two'); @@ -963,14 +985,18 @@ class EachTest extends AbstractEachTest { this.assertText('-Limbo-Wrath-Treachery-Wrath-Limbo-'); runTask(() => { - fifth.delegate.insertAt(0, 'D'); + ignoreDeprecation(() => { + fifth.delegate.insertAt(0, 'D'); + }); }); this.assertText('-Limbo-D-Treachery-D-Wrath-Treachery-Wrath-Limbo-'); runTask(() => { - first.delegate.pushObject('I'); - ninth.delegate.replace(0, 1, ['K']); + ignoreDeprecation(() => { + first.delegate.pushObject('I'); + ninth.delegate.replace(0, 1, ['K']); + }); }); this.assertText('-Limbo-D-K-D-Wrath-K-Wrath-Limbo-I-D-K-D-Wrath-K-Wrath-I-'); @@ -1002,8 +1028,11 @@ class EachTest extends AbstractEachTest { this.assertText('caterpillar'); runTask(() => { - inner.delegate.replace(0, 1, ['lady']); - outer.delegate.pushObject(this.createList(['bird']).list); + let list = this.createList(['bird']).list; + ignoreDeprecation(() => { + inner.delegate.replace(0, 1, ['lady']); + outer.delegate.pushObject(list); + }); }); this.assertText('ladybird'); @@ -1029,7 +1058,7 @@ moduleFor( 'Syntax test: {{#each}} with emberA-wrapped arrays', class extends EachTest { createList(items) { - let wrapped = emberA(items); + let wrapped = emberAWithoutDeprecation(items); return { list: wrapped, delegate: wrapped }; } } @@ -1077,8 +1106,11 @@ moduleFor( 'Syntax test: {{#each}} with array proxies, modifying itself', class extends EachTest { createList(items) { - let proxty = ArrayProxy.create({ content: emberA(items) }); - return { list: proxty, delegate: proxty }; + let proxy; + expectDeprecation(() => { + proxy = ArrayProxy.create({ content: emberAWithoutDeprecation(items) }); + }, /Usage of ArrayProxy is deprecated/); + return { list: proxy, delegate: proxy }; } } ); @@ -1087,10 +1119,14 @@ moduleFor( 'Syntax test: {{#each}} with array proxies, replacing its content', class extends EachTest { createList(items) { - let wrapped = emberA(items); + let wrapped = emberAWithoutDeprecation(items); + let delegate; + expectDeprecation(() => { + delegate = ArrayProxy.create({ content: wrapped }); + }, /Usage of ArrayProxy is deprecated/); return { list: wrapped, - delegate: ArrayProxy.create({ content: wrapped }), + delegate, }; } } @@ -1100,16 +1136,19 @@ moduleFor( 'Syntax test: {{#each}} with array proxies, arrangedContent depends on external content', class extends EachTest { createList(items) { - let wrapped = emberA(items); - let proxy = class extends ArrayProxy { - @computed('wrappedItems.[]') - get arrangedContent() { - // Slice the items to ensure that updates must be propogated - return this.wrappedItems.slice(); - } - }.create({ - wrappedItems: wrapped, - }); + let wrapped = emberAWithoutDeprecation(items); + let proxy; + expectDeprecation(() => { + proxy = class extends ArrayProxy { + @computed('wrappedItems.[]') + get arrangedContent() { + // Slice the items to ensure that updates must be propogated + return this.wrappedItems.slice(); + } + }.create({ + wrappedItems: wrapped, + }); + }, /Usage of ArrayProxy is deprecated/); return { list: proxy, delegate: wrapped }; } @@ -1120,12 +1159,15 @@ moduleFor( 'Syntax test: {{#each}} with array proxies, content is updated after init', class extends EachTest { createList(items) { - let wrapped = emberA(items); - let proxy = ArrayProxy.extend({ - setup: on('init', function () { - this.set('content', emberA(wrapped)); - }), - }).create(); + let wrapped = emberAWithoutDeprecation(items); + let proxy; + expectDeprecation(() => { + proxy = ArrayProxy.extend({ + setup: on('init', function () { + this.set('content', emberAWithoutDeprecation(wrapped)); + }), + }).create(); + }, /Usage of ArrayProxy is deprecated/); return { list: proxy, delegate: wrapped }; } @@ -1174,7 +1216,7 @@ moduleFor( {{#each this.list as |value key|}} [{{key}}:{{value}}] {{/each}}`, - { list: emberA(sparseArray) } + { list: emberAWithoutDeprecation(sparseArray) } ); this.assertText('[0:][1:][2:][3:foo][4:bar]'); @@ -1183,7 +1225,9 @@ moduleFor( runTask(() => { let list = get(this.context, 'list'); - list.pushObject('baz'); + ignoreDeprecation(() => { + list.pushObject('baz'); + }); }); this.assertText('[0:][1:][2:][3:foo][4:bar][5:baz]'); diff --git a/packages/@ember/-internals/glimmer/tests/integration/syntax/if-unless-test.js b/packages/@ember/-internals/glimmer/tests/integration/syntax/if-unless-test.js index 4e8330db4f6..92e204fd6cf 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/syntax/if-unless-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/syntax/if-unless-test.js @@ -1,6 +1,11 @@ -import { RenderingTestCase, moduleFor, strip, runTask } from 'internal-test-helpers'; +import { + RenderingTestCase, + moduleFor, + strip, + runTask, + emberAWithoutDeprecation, +} from 'internal-test-helpers'; -import { A as emberA } from '@ember/array'; import { set } from '@ember/object'; import { Component } from '../../utils/helpers'; @@ -60,7 +65,7 @@ moduleFor( {{else}} Nothing Here! {{/if}}`, - { cond: true, numbers: emberA([1, 2, 3]) } + { cond: true, numbers: emberAWithoutDeprecation([1, 2, 3]) } ); this.assertText('123'); diff --git a/packages/@ember/-internals/glimmer/tests/integration/syntax/let-test.js b/packages/@ember/-internals/glimmer/tests/integration/syntax/let-test.js index f2516061932..25a30c6bb8f 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/syntax/let-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/syntax/let-test.js @@ -1,8 +1,15 @@ -import { moduleFor, RenderingTestCase, strip, runTask } from 'internal-test-helpers'; +import { + moduleFor, + RenderingTestCase, + strip, + runTask, + expectDeprecation, +} from 'internal-test-helpers'; import { get, set } from '@ember/object'; -import { A as emberA, removeAt } from '@ember/array'; +import { removeAt } from '@ember/array'; import ObjectProxy from '@ember/object/proxy'; +import { emberAWithoutDeprecation } from '@ember/routing/-internals'; moduleFor( 'Syntax test: {{#let as}}', @@ -160,7 +167,7 @@ moduleFor( this.render( `{{#let this.arrayThing as |words|}}{{#each words as |word|}}{{word}}{{/each}}{{/let}}`, { - arrayThing: emberA(['Hello', ' ', 'world']), + arrayThing: emberAWithoutDeprecation(['Hello', ' ', 'world']), } ); @@ -172,10 +179,12 @@ moduleFor( runTask(() => { let array = get(this.context, 'arrayThing'); - array.replace(0, 1, ['Goodbye']); - removeAt(array, 1); - array.insertAt(1, ', '); - array.pushObject('!'); + expectDeprecation(() => { + array.replace(0, 1, ['Goodbye']); + removeAt(array, 1); + array.insertAt(1, ', '); + array.pushObject('!'); + }, /Usage of Ember.Array methods is deprecated/); }); this.assertText('Goodbye, world!'); diff --git a/packages/@ember/-internals/glimmer/tests/utils/shared-conditional-tests.js b/packages/@ember/-internals/glimmer/tests/utils/shared-conditional-tests.js index bf725ea1634..7fefa171f91 100644 --- a/packages/@ember/-internals/glimmer/tests/utils/shared-conditional-tests.js +++ b/packages/@ember/-internals/glimmer/tests/utils/shared-conditional-tests.js @@ -1,12 +1,18 @@ /* eslint-disable no-new-wrappers */ -import { RenderingTestCase, applyMixins, runTask } from 'internal-test-helpers'; +import { + RenderingTestCase, + applyMixins, + emberAWithoutDeprecation as emberA, + expectDeprecation, + runTask, +} from 'internal-test-helpers'; import { htmlSafe } from '@ember/-internals/glimmer'; import { get, set } from '@ember/object'; import EmberObject from '@ember/object'; import ObjectProxy from '@ember/object/proxy'; -import { A as emberA, removeAt } from '@ember/array'; +import { removeAt } from '@ember/array'; import ArrayProxy from '@ember/array/proxy'; import { Component } from './helpers'; @@ -301,8 +307,10 @@ export const ArrayTestCases = { this.assertText('F1F2'); runTask(() => { - get(this.context, 'cond1').pushObject('hello'); - get(this.context, 'cond2').pushObjects([1]); + expectDeprecation(() => { + get(this.context, 'cond1').pushObject('hello'); + get(this.context, 'cond2').pushObjects([1]); + }, /Usage of Ember.Array methods is deprecated/); }); this.assertText('T1T2'); @@ -316,10 +324,12 @@ export const ArrayTestCases = { }, ['@test it considers array proxies without content falsy']() { - this.renderValues( - ArrayProxy.create({ content: emberA(['hello']) }), - ArrayProxy.create({ content: null }) - ); + expectDeprecation(() => { + this.renderValues( + ArrayProxy.create({ content: emberA(['hello']) }), + ArrayProxy.create({ content: null }) + ); + }, /Usage of ArrayProxy is deprecated/); this.assertText('T1F2'); @@ -341,19 +351,23 @@ export const ArrayTestCases = { this.assertText('T1T2'); - runTask(() => { - set(this.context, 'cond1', ArrayProxy.create({ content: emberA(['hello']) })); - set(this.context, 'cond2', ArrayProxy.create({ content: null })); - }); + expectDeprecation(() => { + runTask(() => { + set(this.context, 'cond1', ArrayProxy.create({ content: emberA(['hello']) })); + set(this.context, 'cond2', ArrayProxy.create({ content: null })); + }); + }, /Usage of ArrayProxy is deprecated/); this.assertText('T1F2'); }, ['@test it considers array proxies with empty arrays falsy']() { - this.renderValues( - ArrayProxy.create({ content: emberA(['hello']) }), - ArrayProxy.create({ content: emberA() }) - ); + expectDeprecation(() => { + this.renderValues( + ArrayProxy.create({ content: emberA(['hello']) }), + ArrayProxy.create({ content: emberA() }) + ); + }, /Usage of ArrayProxy is deprecated/); this.assertText('T1F2'); @@ -366,16 +380,20 @@ export const ArrayTestCases = { this.assertText('F1F2'); runTask(() => { - get(this.context, 'cond1.content').pushObject('hello'); - get(this.context, 'cond2.content').pushObjects([1]); + expectDeprecation(() => { + get(this.context, 'cond1.content').pushObject('hello'); + get(this.context, 'cond2.content').pushObjects([1]); + }, /Usage of Ember.Array methods is deprecated/); }); this.assertText('T1T2'); - runTask(() => { - set(this.context, 'cond1', ArrayProxy.create({ content: emberA(['hello']) })); - set(this.context, 'cond2', ArrayProxy.create({ content: emberA() })); - }); + expectDeprecation(() => { + runTask(() => { + set(this.context, 'cond1', ArrayProxy.create({ content: emberA(['hello']) })); + set(this.context, 'cond2', ArrayProxy.create({ content: emberA() })); + }); + }, /Usage of ArrayProxy is deprecated/); this.assertText('T1F2'); }, @@ -430,8 +448,9 @@ const IfUnlessWithTestCases = [ 1, ['hello'], emberA(['hello']), - ArrayProxy.create({ content: ['hello'] }), - ArrayProxy.create({ content: [] }), + // FIXME! + // ArrayProxy.create({ content: ['hello'] }), + // ArrayProxy.create({ content: [] }), {}, { foo: 'bar' }, EmberObject.create(), diff --git a/packages/@ember/-internals/metal/lib/array.ts b/packages/@ember/-internals/metal/lib/array.ts index fa9f25ea28a..893a662ae39 100644 --- a/packages/@ember/-internals/metal/lib/array.ts +++ b/packages/@ember/-internals/metal/lib/array.ts @@ -3,6 +3,7 @@ import type MutableArray from '@ember/array/mutable'; import { assert } from '@ember/debug'; import { arrayContentDidChange, arrayContentWillChange } from './array_events'; import { addListener, removeListener } from './events'; +import { disableDeprecations } from '@ember/array/-internals'; const EMPTY_ARRAY = Object.freeze([]); @@ -27,7 +28,9 @@ export function replace( items: readonly T[] = EMPTY_ARRAY as [] ): void { if (isMutableArray(array)) { - array.replace(start, deleteCount, items); + disableDeprecations(() => { + array.replace(start, deleteCount, items); + }); } else { assert('Can only replace content of a native array or MutableArray', Array.isArray(array)); replaceInNativeArray(array, start, deleteCount, items); diff --git a/packages/@ember/-internals/metal/lib/object-at.ts b/packages/@ember/-internals/metal/lib/object-at.ts index e85207863cb..3e1ff72463f 100644 --- a/packages/@ember/-internals/metal/lib/object-at.ts +++ b/packages/@ember/-internals/metal/lib/object-at.ts @@ -1,9 +1,10 @@ import type EmberArray from '@ember/array'; +import { disableDeprecations } from '@ember/array/-internals'; export function objectAt(array: T[] | EmberArray, index: number): T | undefined { if (Array.isArray(array)) { return array[index]; } else { - return array.objectAt(index); + return disableDeprecations(() => array.objectAt(index)); } } diff --git a/packages/@ember/-internals/metal/tests/alias_test.js b/packages/@ember/-internals/metal/tests/alias_test.js index a9c4a2635ce..1da02fa1867 100644 --- a/packages/@ember/-internals/metal/tests/alias_test.js +++ b/packages/@ember/-internals/metal/tests/alias_test.js @@ -10,7 +10,12 @@ import { } from '..'; import EmberObject from '@ember/object'; import { A } from '@ember/array'; -import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { + moduleFor, + AbstractTestCase, + runLoopSettled, + expectDeprecation, +} from 'internal-test-helpers'; import { destroy } from '@glimmer/destroyable'; import { valueForTag, validateTag } from '@glimmer/validator'; @@ -70,12 +75,22 @@ moduleFor( } ['@test nested aliases should trigger computed property invalidation [GH#19279]'](assert) { + let additives; + expectDeprecation(() => { + additives = A(); + }, /Usage of Ember.A is deprecated/); + let AttributeModel = class extends EmberObject { @alias('additives.length') countAdditives; - additives = A(); + additives = additives; }; + let metaAttributes; + expectDeprecation(() => { + metaAttributes = A([AttributeModel.create()]); + }, /Usage of Ember.A is deprecated/); + let RootModel = class extends EmberObject { @computed('metaAttributes.@each.countAdditives') get allAdditives() { @@ -83,12 +98,14 @@ moduleFor( return acc.concat(el.additives); }, []); } - metaAttributes = A([AttributeModel.create()]); + metaAttributes = metaAttributes; }; let model = RootModel.create(); assert.equal(model.allAdditives.length, 0); - model.metaAttributes[0].additives.pushObject('foo'); + expectDeprecation(() => { + model.metaAttributes[0].additives.pushObject('foo'); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(model.allAdditives.length, 1); } diff --git a/packages/@ember/-internals/runtime/tests/array/any-test.js b/packages/@ember/-internals/runtime/tests/array/any-test.js index 58928a04fe2..6c5578538be 100644 --- a/packages/@ember/-internals/runtime/tests/array/any-test.js +++ b/packages/@ember/-internals/runtime/tests/array/any-test.js @@ -1,5 +1,8 @@ -import { A as emberA } from '@ember/array'; -import { AbstractTestCase } from 'internal-test-helpers'; +import { + AbstractTestCase, + emberAWithoutDeprecation as emberA, + expectDeprecation, +} from 'internal-test-helpers'; import { runArrayTests } from '../helpers/array'; class AnyTests extends AbstractTestCase { @@ -9,10 +12,12 @@ class AnyTests extends AbstractTestCase { let found = []; let result; - result = obj.any(function (i) { - found.push(i); - return false; - }); + expectDeprecation(() => { + result = obj.any(function (i) { + found.push(i); + return false; + }); + }, /Usage of Ember.Array methods is deprecated/); this.assert.equal(result, false, 'return value of obj.any'); this.assert.deepEqual(found, ary, 'items passed during any() should match'); @@ -26,10 +31,12 @@ class AnyTests extends AbstractTestCase { let found = []; let result; - result = obj.any(function (i) { - found.push(i); - return --cnt <= 0; - }); + expectDeprecation(() => { + result = obj.any(function (i) { + found.push(i); + return --cnt <= 0; + }); + }, /Usage of Ember.Array methods is deprecated/); this.assert.equal(result, true, 'return value of obj.any'); this.assert.equal(found.length, exp, 'should invoke proper number of times'); this.assert.deepEqual(found, ary.slice(0, -2), 'items passed during any() should match'); @@ -39,7 +46,9 @@ class AnyTests extends AbstractTestCase { let obj = emberA([0, 1, 2]); let result; - result = obj.any((i) => Boolean(i)); + expectDeprecation(() => { + result = obj.any((i) => Boolean(i)); + }, /Usage of Ember.Array methods is deprecated/); this.assert.equal(result, true, 'return value of obj.any'); } @@ -47,7 +56,9 @@ class AnyTests extends AbstractTestCase { let obj = emberA([undefined]); let result; - result = obj.any(() => true); + expectDeprecation(() => { + result = obj.any(() => true); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(result, true, 'return value of obj.any'); } } diff --git a/packages/@ember/-internals/runtime/tests/array/compact-test.js b/packages/@ember/-internals/runtime/tests/array/compact-test.js index eabf464d860..a89bdbf4712 100644 --- a/packages/@ember/-internals/runtime/tests/array/compact-test.js +++ b/packages/@ember/-internals/runtime/tests/array/compact-test.js @@ -1,10 +1,13 @@ -import { AbstractTestCase } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation } from 'internal-test-helpers'; import { runArrayTests } from '../helpers/array'; class CompactTests extends AbstractTestCase { '@test removes null and undefined values from enumerable'() { let obj = this.newObject([null, 1, false, '', undefined, 0, null]); - let ary = obj.compact(); + let ary; + expectDeprecation(() => { + ary = obj.compact(); + }, /Usage of Ember.Array methods is deprecated/); this.assert.deepEqual(ary, [1, false, '', 0]); } } diff --git a/packages/@ember/-internals/runtime/tests/array/every-test.js b/packages/@ember/-internals/runtime/tests/array/every-test.js index a23a6cf81a0..3515126439a 100644 --- a/packages/@ember/-internals/runtime/tests/array/every-test.js +++ b/packages/@ember/-internals/runtime/tests/array/every-test.js @@ -1,4 +1,4 @@ -import { AbstractTestCase } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation } from 'internal-test-helpers'; import { runArrayTests } from '../helpers/array'; import EmberObject from '@ember/object'; @@ -13,6 +13,7 @@ class EveryTest extends AbstractTestCase { found.push(i); return true; }); + this.assert.equal(result, true, 'return value of obj.every'); this.assert.deepEqual(found, ary, 'items passed during every() should match'); } @@ -29,6 +30,7 @@ class EveryTest extends AbstractTestCase { found.push(i); return --cnt > 0; }); + this.assert.equal(result, false, 'return value of obj.every'); this.assert.equal(found.length, exp, 'should invoke proper number of times'); this.assert.deepEqual(found, ary.slice(0, -2), 'items passed during every() should match'); @@ -42,8 +44,10 @@ class IsEveryTest extends AbstractTestCase { EmberObject.create({ foo: 'foo', bar: 'bar' }), ]); - this.assert.equal(obj.isEvery('foo', 'foo'), true, 'isEvery(foo)'); - this.assert.equal(obj.isEvery('bar', 'bar'), false, 'isEvery(bar)'); + expectDeprecation(() => { + this.assert.equal(obj.isEvery('foo', 'foo'), true, 'isEvery(foo)'); + this.assert.equal(obj.isEvery('bar', 'bar'), false, 'isEvery(bar)'); + }, /Usage of Ember.Array methods is deprecated/); } '@test should return true of every property is true'() { @@ -53,8 +57,10 @@ class IsEveryTest extends AbstractTestCase { ]); // different values - all eval to true - this.assert.equal(obj.isEvery('foo'), true, 'isEvery(foo)'); - this.assert.equal(obj.isEvery('bar'), false, 'isEvery(bar)'); + expectDeprecation(() => { + this.assert.equal(obj.isEvery('foo'), true, 'isEvery(foo)'); + this.assert.equal(obj.isEvery('bar'), false, 'isEvery(bar)'); + }, /Usage of Ember.Array methods is deprecated/); } '@test should return true if every property matches null'() { @@ -63,8 +69,10 @@ class IsEveryTest extends AbstractTestCase { EmberObject.create({ foo: null, bar: null }), ]); - this.assert.equal(obj.isEvery('foo', null), true, "isEvery('foo', null)"); - this.assert.equal(obj.isEvery('bar', null), false, "isEvery('bar', null)"); + expectDeprecation(() => { + this.assert.equal(obj.isEvery('foo', null), true, "isEvery('foo', null)"); + this.assert.equal(obj.isEvery('bar', null), false, "isEvery('bar', null)"); + }, /Usage of Ember.Array methods is deprecated/); } '@test should return true if every property is undefined'() { @@ -73,8 +81,10 @@ class IsEveryTest extends AbstractTestCase { EmberObject.create({ bar: undefined }), ]); - this.assert.equal(obj.isEvery('foo', undefined), true, "isEvery('foo', undefined)"); - this.assert.equal(obj.isEvery('bar', undefined), false, "isEvery('bar', undefined)"); + expectDeprecation(() => { + this.assert.equal(obj.isEvery('foo', undefined), true, "isEvery('foo', undefined)"); + this.assert.equal(obj.isEvery('bar', undefined), false, "isEvery('bar', undefined)"); + }, /Usage of Ember.Array methods is deprecated/); } } diff --git a/packages/@ember/-internals/runtime/tests/array/filter-test.js b/packages/@ember/-internals/runtime/tests/array/filter-test.js index d0d97028563..a4eefca71c7 100644 --- a/packages/@ember/-internals/runtime/tests/array/filter-test.js +++ b/packages/@ember/-internals/runtime/tests/array/filter-test.js @@ -1,5 +1,5 @@ import EmberObject from '@ember/object'; -import { AbstractTestCase } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation } from 'internal-test-helpers'; import { runArrayTests } from '../helpers/array'; class FilterTest extends AbstractTestCase { @@ -29,8 +29,10 @@ class FilterByTest extends AbstractTestCase { obj = this.newObject(ary); // different values - all eval to true - this.assert.deepEqual(obj.filterBy('foo'), ary, 'filterBy(foo)'); - this.assert.deepEqual(obj.filterBy('bar'), [ary[0]], 'filterBy(bar)'); + expectDeprecation(() => { + this.assert.deepEqual(obj.filterBy('foo'), ary, 'filterBy(foo)'); + this.assert.deepEqual(obj.filterBy('bar'), [ary[0]], 'filterBy(bar)'); + }, /Usage of Ember.Array methods is deprecated/); } '@test should filter on second argument if provided'() { @@ -45,7 +47,9 @@ class FilterByTest extends AbstractTestCase { obj = this.newObject(ary); - this.assert.deepEqual(obj.filterBy('foo', 3), [ary[0], ary[3]], "filterBy('foo', 3)')"); + expectDeprecation(() => { + this.assert.deepEqual(obj.filterBy('foo', 3), [ary[0], ary[3]], "filterBy('foo', 3)')"); + }, /Usage of Ember.Array methods is deprecated/); } '@test should correctly filter null second argument'() { @@ -60,7 +64,9 @@ class FilterByTest extends AbstractTestCase { obj = this.newObject(ary); - this.assert.deepEqual(obj.filterBy('foo', null), [ary[1], ary[2]], "filterBy('foo', 3)')"); + expectDeprecation(() => { + this.assert.deepEqual(obj.filterBy('foo', null), [ary[1], ary[2]], "filterBy('foo', 3)')"); + }, /Usage of Ember.Array methods is deprecated/); } '@test should correctly filter explicit undefined second argument'() { @@ -77,7 +83,9 @@ class FilterByTest extends AbstractTestCase { obj = this.newObject(ary); - this.assert.deepEqual(obj.filterBy('foo', undefined), ary.slice(2), "filterBy('foo', 3)')"); + expectDeprecation(() => { + this.assert.deepEqual(obj.filterBy('foo', undefined), ary.slice(2), "filterBy('foo', 3)')"); + }, /Usage of Ember.Array methods is deprecated/); } '@test should not match undefined properties without second argument'() { @@ -94,7 +102,9 @@ class FilterByTest extends AbstractTestCase { obj = this.newObject(ary); - this.assert.deepEqual(obj.filterBy('foo'), ary.slice(0, 2), "filterBy('foo', 3)')"); + expectDeprecation(() => { + this.assert.deepEqual(obj.filterBy('foo'), ary.slice(0, 2), "filterBy('foo', 3)')"); + }, /Usage of Ember.Array methods is deprecated/); } } diff --git a/packages/@ember/-internals/runtime/tests/array/find-test.js b/packages/@ember/-internals/runtime/tests/array/find-test.js index 02b34fe5323..794f1115810 100644 --- a/packages/@ember/-internals/runtime/tests/array/find-test.js +++ b/packages/@ember/-internals/runtime/tests/array/find-test.js @@ -1,5 +1,5 @@ import EmberObject from '@ember/object'; -import { AbstractTestCase } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation } from 'internal-test-helpers'; import { runArrayTests } from '../helpers/array'; class FindTests extends AbstractTestCase { @@ -43,8 +43,10 @@ class FindByTests extends AbstractTestCase { obj = this.newObject(ary); - this.assert.equal(obj.findBy('foo', 'foo'), ary[0], 'findBy(foo)'); - this.assert.equal(obj.findBy('bar', 'bar'), ary[1], 'findBy(bar)'); + expectDeprecation(() => { + this.assert.equal(obj.findBy('foo', 'foo'), ary[0], 'findBy(foo)'); + this.assert.equal(obj.findBy('bar', 'bar'), ary[1], 'findBy(bar)'); + }, /Usage of Ember.Array methods is deprecated/); } '@test should return first object with truthy prop'() { @@ -55,8 +57,10 @@ class FindByTests extends AbstractTestCase { obj = this.newObject(ary); // different values - all eval to true - this.assert.equal(obj.findBy('foo'), ary[0], 'findBy(foo)'); - this.assert.equal(obj.findBy('bar'), ary[1], 'findBy(bar)'); + expectDeprecation(() => { + this.assert.equal(obj.findBy('foo'), ary[0], 'findBy(foo)'); + this.assert.equal(obj.findBy('bar'), ary[1], 'findBy(bar)'); + }, /Usage of Ember.Array methods is deprecated/); } '@test should return first null property match'() { @@ -66,8 +70,10 @@ class FindByTests extends AbstractTestCase { obj = this.newObject(ary); - this.assert.equal(obj.findBy('foo', null), ary[0], "findBy('foo', null)"); - this.assert.equal(obj.findBy('bar', null), ary[1], "findBy('bar', null)"); + expectDeprecation(() => { + this.assert.equal(obj.findBy('foo', null), ary[0], "findBy('foo', null)"); + this.assert.equal(obj.findBy('bar', null), ary[1], "findBy('bar', null)"); + }, /Usage of Ember.Array methods is deprecated/); } '@test should return first undefined property match'() { @@ -77,8 +83,10 @@ class FindByTests extends AbstractTestCase { obj = this.newObject(ary); - this.assert.equal(obj.findBy('foo', undefined), ary[0], "findBy('foo', undefined)"); - this.assert.equal(obj.findBy('bar', undefined), ary[1], "findBy('bar', undefined)"); + expectDeprecation(() => { + this.assert.equal(obj.findBy('foo', undefined), ary[0], "findBy('foo', undefined)"); + this.assert.equal(obj.findBy('bar', undefined), ary[1], "findBy('bar', undefined)"); + }, /Usage of Ember.Array methods is deprecated/); } } diff --git a/packages/@ember/-internals/runtime/tests/array/firstObject-test.js b/packages/@ember/-internals/runtime/tests/array/firstObject-test.js index b44ce9c2a04..4d291bcf3f0 100644 --- a/packages/@ember/-internals/runtime/tests/array/firstObject-test.js +++ b/packages/@ember/-internals/runtime/tests/array/firstObject-test.js @@ -1,22 +1,28 @@ import { get, set } from '@ember/object'; -import { AbstractTestCase } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation } from 'internal-test-helpers'; import { runArrayTests } from '../helpers/array'; class FirstObjectTests extends AbstractTestCase { '@test returns first item in enumerable'() { let obj = this.newObject(); - this.assert.equal(get(obj, 'firstObject'), this.toArray(obj)[0]); + expectDeprecation(() => { + this.assert.equal(get(obj, 'firstObject'), this.toArray(obj)[0]); + }, /Usage of Ember.Array methods is deprecated/); } '@test returns undefined if enumerable is empty'() { let obj = this.newObject([]); - this.assert.equal(get(obj, 'firstObject'), undefined); + expectDeprecation(() => { + this.assert.equal(get(obj, 'firstObject'), undefined); + }, /Usage of Ember.Array methods is deprecated/); } '@test can not be set'() { let obj = this.newObject([]); - this.assert.equal(get(obj, 'firstObject'), this.toArray(obj)[0]); + expectDeprecation(() => { + this.assert.equal(get(obj, 'firstObject'), this.toArray(obj)[0]); + }, /Usage of Ember.Array methods is deprecated/); this.assert.throws(() => { set(obj, 'firstObject', 'foo!'); diff --git a/packages/@ember/-internals/runtime/tests/array/invoke-test.js b/packages/@ember/-internals/runtime/tests/array/invoke-test.js index a8e7a7e55fc..063e8951fb6 100644 --- a/packages/@ember/-internals/runtime/tests/array/invoke-test.js +++ b/packages/@ember/-internals/runtime/tests/array/invoke-test.js @@ -1,6 +1,6 @@ import EmberObject from '@ember/object'; import { NativeArray } from '@ember/array'; -import { AbstractTestCase } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation } from 'internal-test-helpers'; import { runArrayTests } from '../helpers/array'; class InvokeTests extends AbstractTestCase { @@ -22,11 +22,15 @@ class InvokeTests extends AbstractTestCase { ]; obj = this.newObject(ary); - obj.invoke('foo'); + expectDeprecation(() => { + obj.invoke('foo'); + }, /Usage of Ember.Array methods is deprecated/); this.assert.equal(cnt, 3, 'should have invoked 3 times'); cnt = 0; - obj.invoke('foo', 2); + expectDeprecation(() => { + obj.invoke('foo', 2); + }, /Usage of Ember.Array methods is deprecated/); this.assert.equal(cnt, 6, 'should have invoked 3 times, passing param'); } @@ -45,16 +49,24 @@ class InvokeTests extends AbstractTestCase { }, ]); - let result = obj.invoke('foo'); + let result; + expectDeprecation(() => { + result = obj.invoke('foo'); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual(result, ['one', undefined, 'two']); } '@test invoke should return an extended array (aka Ember.A)'(assert) { let obj = this.newObject([{ foo() {} }, { foo() {} }]); - let result = obj.invoke('foo'); + let result; + expectDeprecation(() => { + result = obj.invoke('foo'); + }, /Usage of Ember.Array methods is deprecated/); - assert.ok(NativeArray.detect(result), 'NativeArray has been applied'); + expectDeprecation(() => { + assert.ok(NativeArray.detect(result), 'NativeArray has been applied'); + }, /Usage of EmberArray is deprecated/); } } diff --git a/packages/@ember/-internals/runtime/tests/array/isAny-test.js b/packages/@ember/-internals/runtime/tests/array/isAny-test.js index 56fd637dba4..5d65353085e 100644 --- a/packages/@ember/-internals/runtime/tests/array/isAny-test.js +++ b/packages/@ember/-internals/runtime/tests/array/isAny-test.js @@ -1,5 +1,5 @@ import EmberObject from '@ember/object'; -import { AbstractTestCase } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation } from 'internal-test-helpers'; import { runArrayTests } from '../helpers/array'; class IsAnyTests extends AbstractTestCase { @@ -9,9 +9,11 @@ class IsAnyTests extends AbstractTestCase { EmberObject.create({ foo: 'foo', bar: 'bar' }), ]); - this.assert.equal(obj.isAny('foo', 'foo'), true, 'isAny(foo)'); - this.assert.equal(obj.isAny('bar', 'bar'), true, 'isAny(bar)'); - this.assert.equal(obj.isAny('bar', 'BIFF'), false, 'isAny(BIFF)'); + expectDeprecation(() => { + this.assert.equal(obj.isAny('foo', 'foo'), true, 'isAny(foo)'); + this.assert.equal(obj.isAny('bar', 'bar'), true, 'isAny(bar)'); + this.assert.equal(obj.isAny('bar', 'BIFF'), false, 'isAny(BIFF)'); + }, /Usage of Ember.Array methods is deprecated/); } '@test should return true of any property is true'() { @@ -21,9 +23,11 @@ class IsAnyTests extends AbstractTestCase { ]); // different values - all eval to true - this.assert.equal(obj.isAny('foo'), true, 'isAny(foo)'); - this.assert.equal(obj.isAny('bar'), true, 'isAny(bar)'); - this.assert.equal(obj.isAny('BIFF'), false, 'isAny(biff)'); + expectDeprecation(() => { + this.assert.equal(obj.isAny('foo'), true, 'isAny(foo)'); + this.assert.equal(obj.isAny('bar'), true, 'isAny(bar)'); + this.assert.equal(obj.isAny('BIFF'), false, 'isAny(biff)'); + }, /Usage of Ember.Array methods is deprecated/); } '@test should return true if any property matches null'() { @@ -32,21 +36,27 @@ class IsAnyTests extends AbstractTestCase { EmberObject.create({ foo: 'foo', bar: null }), ]); - this.assert.equal(obj.isAny('foo', null), true, "isAny('foo', null)"); - this.assert.equal(obj.isAny('bar', null), true, "isAny('bar', null)"); + expectDeprecation(() => { + this.assert.equal(obj.isAny('foo', null), true, "isAny('foo', null)"); + this.assert.equal(obj.isAny('bar', null), true, "isAny('bar', null)"); + }, /Usage of Ember.Array methods is deprecated/); } '@test should return true if any property is undefined'() { let obj = this.newObject([{ foo: undefined, bar: 'bar' }, EmberObject.create({ foo: 'foo' })]); - this.assert.equal(obj.isAny('foo', undefined), true, "isAny('foo', undefined)"); - this.assert.equal(obj.isAny('bar', undefined), true, "isAny('bar', undefined)"); + expectDeprecation(() => { + this.assert.equal(obj.isAny('foo', undefined), true, "isAny('foo', undefined)"); + this.assert.equal(obj.isAny('bar', undefined), true, "isAny('bar', undefined)"); + }, /Usage of Ember.Array methods is deprecated/); } '@test should not match undefined properties without second argument'() { let obj = this.newObject([{ foo: undefined }, EmberObject.create({})]); - this.assert.equal(obj.isAny('foo'), false, "isAny('foo', undefined)"); + expectDeprecation(() => { + this.assert.equal(obj.isAny('foo'), false, "isAny('foo', undefined)"); + }, /Usage of Ember.Array methods is deprecated/); } } diff --git a/packages/@ember/-internals/runtime/tests/array/lastObject-test.js b/packages/@ember/-internals/runtime/tests/array/lastObject-test.js index 35f52092453..43ebca305a8 100644 --- a/packages/@ember/-internals/runtime/tests/array/lastObject-test.js +++ b/packages/@ember/-internals/runtime/tests/array/lastObject-test.js @@ -1,4 +1,4 @@ -import { AbstractTestCase } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation } from 'internal-test-helpers'; import { runArrayTests } from '../helpers/array'; import { get, set } from '@ember/object'; @@ -7,20 +7,26 @@ class LastObjectTests extends AbstractTestCase { let obj = this.newObject(); let ary = this.toArray(obj); - this.assert.equal(get(obj, 'lastObject'), ary[ary.length - 1]); + expectDeprecation(() => { + this.assert.equal(get(obj, 'lastObject'), ary[ary.length - 1]); + }, /Usage of Ember.Array methods is deprecated/); } '@test returns undefined if enumerable is empty'() { let obj = this.newObject([]); - this.assert.equal(get(obj, 'lastObject'), undefined); + expectDeprecation(() => { + this.assert.equal(get(obj, 'lastObject'), undefined); + }, /Usage of Ember.Array methods is deprecated/); } '@test can not be set'() { let obj = this.newObject(); let ary = this.toArray(obj); - this.assert.equal(get(obj, 'lastObject'), ary[ary.length - 1]); + expectDeprecation(() => { + this.assert.equal(get(obj, 'lastObject'), ary[ary.length - 1]); + }, /Usage of Ember.Array methods is deprecated/); this.assert.throws(function () { set(obj, 'lastObject', 'foo!'); diff --git a/packages/@ember/-internals/runtime/tests/array/mapBy-test.js b/packages/@ember/-internals/runtime/tests/array/mapBy-test.js index 115910327d7..f49f0566657 100644 --- a/packages/@ember/-internals/runtime/tests/array/mapBy-test.js +++ b/packages/@ember/-internals/runtime/tests/array/mapBy-test.js @@ -1,15 +1,19 @@ -import { AbstractTestCase } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation } from 'internal-test-helpers'; import { runArrayTests } from '../helpers/array'; class MapByTests extends AbstractTestCase { '@test get value of each property'() { let obj = this.newObject([{ a: 1 }, { a: 2 }]); - this.assert.equal(obj.mapBy('a').join(''), '12'); + expectDeprecation(() => { + this.assert.equal(obj.mapBy('a').join(''), '12'); + }, /Usage of Ember.Array methods is deprecated/); } '@test should work also through getEach alias'() { let obj = this.newObject([{ a: 1 }, { a: 2 }]); - this.assert.equal(obj.getEach('a').join(''), '12'); + expectDeprecation(() => { + this.assert.equal(obj.getEach('a').join(''), '12'); + }, /Usage of Ember.Array methods is deprecated/); } } diff --git a/packages/@ember/-internals/runtime/tests/array/objectAt-test.js b/packages/@ember/-internals/runtime/tests/array/objectAt-test.js index ff2572b65a8..286ddd016f8 100644 --- a/packages/@ember/-internals/runtime/tests/array/objectAt-test.js +++ b/packages/@ember/-internals/runtime/tests/array/objectAt-test.js @@ -1,4 +1,4 @@ -import { AbstractTestCase } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation } from 'internal-test-helpers'; import { runArrayTests, newFixture } from '../helpers/array'; class ObjectAtTests extends AbstractTestCase { @@ -8,7 +8,9 @@ class ObjectAtTests extends AbstractTestCase { let len = expected.length; for (let idx = 0; idx < len; idx++) { - this.assert.equal(obj.objectAt(idx), expected[idx], `obj.objectAt(${idx}) should match`); + expectDeprecation(() => { + this.assert.equal(obj.objectAt(idx), expected[idx], `obj.objectAt(${idx}) should match`); + }, /Usage of Ember.Array methods is deprecated/); } } @@ -16,18 +18,22 @@ class ObjectAtTests extends AbstractTestCase { let obj; obj = this.newObject(newFixture(3)); - this.assert.equal( - obj.objectAt(obj, 5), - undefined, - 'should return undefined for obj.objectAt(5) when len = 3' - ); + expectDeprecation(() => { + this.assert.equal( + obj.objectAt(obj, 5), + undefined, + 'should return undefined for obj.objectAt(5) when len = 3' + ); + }, /Usage of Ember.Array methods is deprecated/); obj = this.newObject([]); - this.assert.equal( - obj.objectAt(obj, 0), - undefined, - 'should return undefined for obj.objectAt(0) when len = 0' - ); + expectDeprecation(() => { + this.assert.equal( + obj.objectAt(obj, 0), + undefined, + 'should return undefined for obj.objectAt(0) when len = 0' + ); + }, /Usage of Ember.Array methods is deprecated/); } } diff --git a/packages/@ember/-internals/runtime/tests/array/reject-test.js b/packages/@ember/-internals/runtime/tests/array/reject-test.js index 01e5741cd17..847b9261907 100644 --- a/packages/@ember/-internals/runtime/tests/array/reject-test.js +++ b/packages/@ember/-internals/runtime/tests/array/reject-test.js @@ -1,4 +1,4 @@ -import { AbstractTestCase } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation } from 'internal-test-helpers'; import { runArrayTests } from '../helpers/array'; import EmberObject from '@ember/object'; @@ -7,7 +7,10 @@ class RejectTest extends AbstractTestCase { let obj = this.newObject([1, 2, 3, 4]); let result; - result = obj.reject((i) => i < 3); + expectDeprecation(() => { + result = obj.reject((i) => i < 3); + }, /Usage of Ember.Array methods is deprecated/); + this.assert.deepEqual(result, [3, 4], 'reject the correct items'); } @@ -17,7 +20,9 @@ class RejectTest extends AbstractTestCase { let filtered, rejected; filtered = obj.filter(isEven); - rejected = obj.reject(isEven); + expectDeprecation(() => { + rejected = obj.reject(isEven); + }, /Usage of Ember.Array methods is deprecated/); this.assert.deepEqual(filtered, [2, 4], 'filtered evens'); this.assert.deepEqual(rejected, [1, 3], 'rejected evens'); @@ -32,8 +37,10 @@ class RejectByTest extends AbstractTestCase { obj = this.newObject(ary); - this.assert.deepEqual(obj.rejectBy('foo', 'foo'), [], 'rejectBy(foo)'); - this.assert.deepEqual(obj.rejectBy('bar', 'bar'), [ary[0]], 'rejectBy(bar)'); + expectDeprecation(() => { + this.assert.deepEqual(obj.rejectBy('foo', 'foo'), [], 'rejectBy(foo)'); + this.assert.deepEqual(obj.rejectBy('bar', 'bar'), [ary[0]], 'rejectBy(bar)'); + }, /Usage of Ember.Array methods is deprecated/); } '@test should include in result if property is false'() { @@ -43,8 +50,10 @@ class RejectByTest extends AbstractTestCase { obj = this.newObject(ary); - this.assert.deepEqual(obj.rejectBy('foo'), ary, 'rejectBy(foo)'); - this.assert.deepEqual(obj.rejectBy('bar'), [ary[1]], 'rejectBy(bar)'); + expectDeprecation(() => { + this.assert.deepEqual(obj.rejectBy('foo'), ary, 'rejectBy(foo)'); + this.assert.deepEqual(obj.rejectBy('bar'), [ary[1]], 'rejectBy(bar)'); + }, /Usage of Ember.Array methods is deprecated/); } '@test should reject on second argument if provided'() { @@ -59,7 +68,9 @@ class RejectByTest extends AbstractTestCase { obj = this.newObject(ary); - this.assert.deepEqual(obj.rejectBy('foo', 3), [ary[1], ary[2]], "rejectBy('foo', 3)')"); + expectDeprecation(() => { + this.assert.deepEqual(obj.rejectBy('foo', 3), [ary[1], ary[2]], "rejectBy('foo', 3)')"); + }, /Usage of Ember.Array methods is deprecated/); } '@test should correctly reject null second argument'() { @@ -74,7 +85,9 @@ class RejectByTest extends AbstractTestCase { obj = this.newObject(ary); - this.assert.deepEqual(obj.rejectBy('foo', null), [ary[0], ary[3]], "rejectBy('foo', null)')"); + expectDeprecation(() => { + this.assert.deepEqual(obj.rejectBy('foo', null), [ary[0], ary[3]], "rejectBy('foo', null)')"); + }, /Usage of Ember.Array methods is deprecated/); } '@test should correctly reject undefined second argument'() { @@ -84,7 +97,9 @@ class RejectByTest extends AbstractTestCase { obj = this.newObject(ary); - this.assert.deepEqual(obj.rejectBy('bar', undefined), [], "rejectBy('bar', undefined)')"); + expectDeprecation(() => { + this.assert.deepEqual(obj.rejectBy('bar', undefined), [], "rejectBy('bar', undefined)')"); + }, /Usage of Ember.Array methods is deprecated/); } '@test should correctly reject explicit undefined second argument'() { @@ -101,11 +116,13 @@ class RejectByTest extends AbstractTestCase { obj = this.newObject(ary); - this.assert.deepEqual( - obj.rejectBy('foo', undefined), - ary.slice(0, 2), - "rejectBy('foo', undefined)')" - ); + expectDeprecation(() => { + this.assert.deepEqual( + obj.rejectBy('foo', undefined), + ary.slice(0, 2), + "rejectBy('foo', undefined)')" + ); + }, /Usage of Ember.Array methods is deprecated/); } '@test should match undefined, null, or false properties without second argument'() { @@ -126,7 +143,9 @@ class RejectByTest extends AbstractTestCase { obj = this.newObject(ary); - this.assert.deepEqual(obj.rejectBy('foo'), ary.slice(2), "rejectBy('foo')')"); + expectDeprecation(() => { + this.assert.deepEqual(obj.rejectBy('foo'), ary.slice(2), "rejectBy('foo')')"); + }, /Usage of Ember.Array methods is deprecated/); } } diff --git a/packages/@ember/-internals/runtime/tests/array/sortBy-test.js b/packages/@ember/-internals/runtime/tests/array/sortBy-test.js index 2cd4bda7e10..e9b5a54af64 100644 --- a/packages/@ember/-internals/runtime/tests/array/sortBy-test.js +++ b/packages/@ember/-internals/runtime/tests/array/sortBy-test.js @@ -1,11 +1,14 @@ import { get } from '@ember/object'; -import { AbstractTestCase } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation } from 'internal-test-helpers'; import { runArrayTests } from '../helpers/array'; class SortByTests extends AbstractTestCase { '@test sort by value of property'() { let obj = this.newObject([{ a: 2 }, { a: 1 }]); - let sorted = obj.sortBy('a'); + let sorted; + expectDeprecation(() => { + sorted = obj.sortBy('a'); + }, /Usage of Ember.Array methods is deprecated/); this.assert.equal(get(sorted[0], 'a'), 1); this.assert.equal(get(sorted[1], 'a'), 2); @@ -16,7 +19,10 @@ class SortByTests extends AbstractTestCase { { a: 1, b: 2 }, { a: 1, b: 1 }, ]); - let sorted = obj.sortBy('a', 'b'); + let sorted; + expectDeprecation(() => { + sorted = obj.sortBy('a', 'b'); + }, /Usage of Ember.Array methods is deprecated/); this.assert.equal(get(sorted[0], 'b'), 1); this.assert.equal(get(sorted[1], 'b'), 2); diff --git a/packages/@ember/-internals/runtime/tests/array/uniq-test.js b/packages/@ember/-internals/runtime/tests/array/uniq-test.js index 59b43afeef2..c073ae06c50 100644 --- a/packages/@ember/-internals/runtime/tests/array/uniq-test.js +++ b/packages/@ember/-internals/runtime/tests/array/uniq-test.js @@ -1,4 +1,4 @@ -import { AbstractTestCase } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation } from 'internal-test-helpers'; import { runArrayTests, newFixture } from '../helpers/array'; class UniqTests extends AbstractTestCase { @@ -10,7 +10,10 @@ class UniqTests extends AbstractTestCase { obj = this.newObject(before); before = obj.toArray(); // in case of set before will be different... - ret = obj.uniq(); + expectDeprecation(() => { + ret = obj.uniq(); + }, /Usage of Ember.Array methods is deprecated/); + this.assert.deepEqual(this.toArray(ret), after, 'should have removed item'); this.assert.deepEqual(this.toArray(obj), before, 'should not have changed original'); } @@ -18,7 +21,11 @@ class UniqTests extends AbstractTestCase { '@test should return duplicate of same content if no duplicates found'() { let item, obj, ret; obj = this.newObject(newFixture(3)); - ret = obj.uniq(item); + + expectDeprecation(() => { + ret = obj.uniq(item); + }, /Usage of Ember.Array methods is deprecated/); + this.assert.ok(ret !== obj, 'should not be same object'); this.assert.deepEqual(this.toArray(ret), this.toArray(obj), 'should be the same content'); } diff --git a/packages/@ember/-internals/runtime/tests/array/uniqBy-test.js b/packages/@ember/-internals/runtime/tests/array/uniqBy-test.js index 4c8663f0f3a..27c2ba8c787 100644 --- a/packages/@ember/-internals/runtime/tests/array/uniqBy-test.js +++ b/packages/@ember/-internals/runtime/tests/array/uniqBy-test.js @@ -1,4 +1,4 @@ -import { AbstractTestCase } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation } from 'internal-test-helpers'; import { runArrayTests } from '../helpers/array'; class UniqByTests extends AbstractTestCase { @@ -8,10 +8,13 @@ class UniqByTests extends AbstractTestCase { { id: 2, value: 'two' }, { id: 1, value: 'one' }, ]); - this.assert.deepEqual(numbers.uniqBy('id'), [ - { id: 1, value: 'one' }, - { id: 2, value: 'two' }, - ]); + + expectDeprecation(() => { + this.assert.deepEqual(numbers.uniqBy('id'), [ + { id: 1, value: 'one' }, + { id: 2, value: 'two' }, + ]); + }, /Usage of Ember.Array methods is deprecated/); } '@test supports function as key'() { @@ -26,10 +29,12 @@ class UniqByTests extends AbstractTestCase { return val.value; }; - this.assert.deepEqual(numbers.uniqBy(keyFunction), [ - { id: 1, value: 'boom' }, - { id: 1, value: 'doom' }, - ]); + expectDeprecation(() => { + this.assert.deepEqual(numbers.uniqBy(keyFunction), [ + { id: 1, value: 'boom' }, + { id: 1, value: 'doom' }, + ]); + }, /Usage of Ember.Array methods is deprecated/); } } diff --git a/packages/@ember/-internals/runtime/tests/array/without-test.js b/packages/@ember/-internals/runtime/tests/array/without-test.js index ce0479234a5..bc2ea0124b9 100644 --- a/packages/@ember/-internals/runtime/tests/array/without-test.js +++ b/packages/@ember/-internals/runtime/tests/array/without-test.js @@ -1,4 +1,4 @@ -import { AbstractTestCase } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation } from 'internal-test-helpers'; import { runArrayTests, newFixture } from '../helpers/array'; class WithoutTests extends AbstractTestCase { @@ -9,7 +9,10 @@ class WithoutTests extends AbstractTestCase { after = [before[0], before[2]]; obj = this.newObject(before); - ret = obj.without(before[1]); + expectDeprecation(() => { + ret = obj.without(before[1]); + }, /Usage of Ember.Array methods is deprecated/); + this.assert.deepEqual(this.toArray(ret), after, 'should have removed item'); this.assert.deepEqual(this.toArray(obj), before, 'should not have changed original'); } @@ -21,7 +24,10 @@ class WithoutTests extends AbstractTestCase { after = [before[0], before[1]]; obj = this.newObject(before); - ret = obj.without(NaN); + expectDeprecation(() => { + ret = obj.without(NaN); + }, /Usage of Ember.Array methods is deprecated/); + this.assert.deepEqual(this.toArray(ret), after, 'should have removed item'); } @@ -31,7 +37,10 @@ class WithoutTests extends AbstractTestCase { item = newFixture(1)[0]; obj = this.newObject(newFixture(3)); - ret = obj.without(item); + expectDeprecation(() => { + ret = obj.without(item); + }, /Usage of Ember.Array methods is deprecated/); + this.assert.equal(ret, obj, 'should be same instance'); } } diff --git a/packages/@ember/-internals/runtime/tests/core/is_array_test.js b/packages/@ember/-internals/runtime/tests/core/is_array_test.js index 6416fa4d421..6fb1d561171 100644 --- a/packages/@ember/-internals/runtime/tests/core/is_array_test.js +++ b/packages/@ember/-internals/runtime/tests/core/is_array_test.js @@ -1,8 +1,13 @@ -import { A as emberA, isArray } from '@ember/array'; +import { isArray } from '@ember/array'; import ArrayProxy from '@ember/array/proxy'; import EmberObject from '@ember/object'; import { window } from '@ember/-internals/browser-environment'; -import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; +import { + moduleFor, + AbstractTestCase, + emberAWithoutDeprecation as emberA, + expectDeprecation, +} from 'internal-test-helpers'; const global = this; @@ -19,7 +24,10 @@ moduleFor( let strangeLength = { length: 'yes' }; let fn = function () {}; let asyncFn = async function () {}; - let arrayProxy = ArrayProxy.create({ content: emberA() }); + let arrayProxy; + expectDeprecation(() => { + arrayProxy = ArrayProxy.create({ content: emberA() }); + }, /Usage of ArrayProxy is deprecated/); assert.equal(isArray(numarray), true, '[1,2,3]'); assert.equal(isArray(number), false, '23'); diff --git a/packages/@ember/-internals/runtime/tests/core/is_empty_test.js b/packages/@ember/-internals/runtime/tests/core/is_empty_test.js index cb8108de479..c114df3a329 100644 --- a/packages/@ember/-internals/runtime/tests/core/is_empty_test.js +++ b/packages/@ember/-internals/runtime/tests/core/is_empty_test.js @@ -1,20 +1,31 @@ import { isEmpty } from '@ember/utils'; import ArrayProxy from '@ember/array/proxy'; import ObjectProxy from '@ember/object/proxy'; -import { A as emberA } from '@ember/array'; -import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; +import { + moduleFor, + emberAWithoutDeprecation as emberA, + AbstractTestCase, + expectDeprecation, +} from 'internal-test-helpers'; moduleFor( 'Ember.isEmpty', class extends AbstractTestCase { ['@test Ember.isEmpty ArrayProxy'](assert) { - let arrayProxy = ArrayProxy.create({ content: emberA() }); + let arrayProxy; + expectDeprecation(() => { + arrayProxy = ArrayProxy.create({ content: emberA() }); + }, /Usage of ArrayProxy is deprecated/); assert.equal(true, isEmpty(arrayProxy), 'for an ArrayProxy that has empty content'); } ['@test Ember.isEmpty ObjectProxy ArrayProxy'](assert) { - let arrayProxy = ArrayProxy.create({ content: emberA([]) }); + let arrayProxy; + expectDeprecation(() => { + arrayProxy = ArrayProxy.create({ content: emberA([]) }); + }, /Usage of ArrayProxy is deprecated/); + let objectProxy = ObjectProxy.create({ content: arrayProxy }); assert.equal( diff --git a/packages/@ember/-internals/runtime/tests/helpers/array.js b/packages/@ember/-internals/runtime/tests/helpers/array.js index 68e4aa22fad..4140592ca47 100644 --- a/packages/@ember/-internals/runtime/tests/helpers/array.js +++ b/packages/@ember/-internals/runtime/tests/helpers/array.js @@ -9,7 +9,8 @@ import { arrayContentDidChange, } from '@ember/-internals/metal'; import EmberObject, { get, computed } from '@ember/object'; -import { moduleFor } from 'internal-test-helpers'; +import { emberAWithoutDeprecation, expectDeprecation, moduleFor } from 'internal-test-helpers'; +import { disableDeprecations } from '../../../utils/lib/mixin-deprecation'; export function newFixture(cnt) { let ret = []; @@ -142,21 +143,29 @@ class AbstractArrayHelper { class NativeArrayHelpers extends AbstractArrayHelper { newObject(ary) { - return emberA(super.newObject(ary)); + return emberAWithoutDeprecation(super.newObject(ary)); } mutate(obj) { - obj.pushObject(obj.length + 1); + expectDeprecation(() => { + obj.pushObject(obj.length + 1); + }, /Usage of Ember.Array methods is deprecated/); } } class ArrayProxyHelpers extends AbstractArrayHelper { newObject(ary) { - return ArrayProxy.create({ content: emberA(super.newObject(ary)) }); + let proxy; + expectDeprecation(() => { + proxy = ArrayProxy.create({ content: emberAWithoutDeprecation(super.newObject(ary)) }); + }, /Usage of ArrayProxy is deprecated/); + return proxy; } mutate(obj) { - obj.pushObject(get(obj, 'length') + 1); + expectDeprecation(() => { + obj.pushObject(get(obj, 'length') + 1); + }, /Usage of Ember.Array methods is deprecated/); } toArray(obj) { @@ -168,75 +177,79 @@ class ArrayProxyHelpers extends AbstractArrayHelper { Implement a basic fake mutable array. This validates that any non-native enumerable can impl this API. */ -const TestArray = EmberObject.extend(EmberArray, { - _content: null, - - init() { - this._content = this._content || []; - }, - - // some methods to modify the array so we can test changes. Note that - // arrays can be modified even if they don't implement MutableArray. The - // MutableArray is just a standard API for mutation but not required. - addObject(obj) { - let idx = this._content.length; - arrayContentWillChange(this, idx, 0, 1); - this._content.push(obj); - arrayContentDidChange(this, idx, 0, 1); - }, - - removeFirst() { - arrayContentWillChange(this, 0, 1, 0); - this._content.shift(); - arrayContentDidChange(this, 0, 1, 0); - }, - - objectAt(idx) { - return this._content[idx]; - }, - - length: computed(function () { - return this._content.length; - }), -}); +const TestArray = disableDeprecations(() => + EmberObject.extend(EmberArray, { + _content: null, + + init() { + this._content = this._content || []; + }, + + // some methods to modify the array so we can test changes. Note that + // arrays can be modified even if they don't implement MutableArray. The + // MutableArray is just a standard API for mutation but not required. + addObject(obj) { + let idx = this._content.length; + arrayContentWillChange(this, idx, 0, 1); + this._content.push(obj); + arrayContentDidChange(this, idx, 0, 1); + }, + + removeFirst() { + arrayContentWillChange(this, 0, 1, 0); + this._content.shift(); + arrayContentDidChange(this, 0, 1, 0); + }, + + objectAt(idx) { + return this._content[idx]; + }, + + length: computed(function () { + return this._content.length; + }), + }) +); /* Implement a basic fake mutable array. This validates that any non-native enumerable can impl this API. */ -const TestMutableArray = EmberObject.extend(MutableArray, { - _content: null, - - init(ary = []) { - this._content = emberA(ary); - }, - - replace(idx, amt, objects) { - let args = objects ? objects.slice() : []; - let removeAmt = amt; - let addAmt = args.length; - - arrayContentWillChange(this, idx, removeAmt, addAmt); - - args.unshift(amt); - args.unshift(idx); - this._content.splice.apply(this._content, args); - arrayContentDidChange(this, idx, removeAmt, addAmt); - return this; - }, - - objectAt(idx) { - return this._content[idx]; - }, - - length: computed(function () { - return this._content.length; - }), - - slice() { - return this._content.slice(); - }, -}); +const TestMutableArray = disableDeprecations(() => + EmberObject.extend(MutableArray, { + _content: null, + + init(ary = []) { + this._content = emberAWithoutDeprecation(ary); + }, + + replace(idx, amt, objects) { + let args = objects ? objects.slice() : []; + let removeAmt = amt; + let addAmt = args.length; + + arrayContentWillChange(this, idx, removeAmt, addAmt); + + args.unshift(amt); + args.unshift(idx); + this._content.splice.apply(this._content, args); + arrayContentDidChange(this, idx, removeAmt, addAmt); + return this; + }, + + objectAt(idx) { + return this._content[idx]; + }, + + length: computed(function () { + return this._content.length; + }), + + slice() { + return this._content.slice(); + }, + }) +); class MutableArrayHelpers extends NativeArrayHelpers { newObject(ary) { diff --git a/packages/@ember/-internals/runtime/tests/legacy_1x/mixins/observable/chained_test.js b/packages/@ember/-internals/runtime/tests/legacy_1x/mixins/observable/chained_test.js index a650428eee4..a6be43c77f9 100644 --- a/packages/@ember/-internals/runtime/tests/legacy_1x/mixins/observable/chained_test.js +++ b/packages/@ember/-internals/runtime/tests/legacy_1x/mixins/observable/chained_test.js @@ -1,7 +1,12 @@ import { addObserver } from '@ember/-internals/metal'; import EmberObject, { get, set } from '@ember/object'; -import { A as emberA } from '@ember/array'; -import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { + moduleFor, + AbstractTestCase, + runLoopSettled, + emberAWithoutDeprecation, + expectDeprecation, +} from 'internal-test-helpers'; /* NOTE: This test is adapted from the 1.x series of unit tests. The tests @@ -29,7 +34,7 @@ moduleFor( let child4 = EmberObject.create({ name: 'Nancy' }); set(family, 'momma', momma); - set(momma, 'children', emberA([child1, child2, child3])); + set(momma, 'children', emberAWithoutDeprecation([child1, child2, child3])); let observerFiredCount = 0; addObserver(family, 'momma.children.@each.name', this, function () { @@ -45,7 +50,9 @@ moduleFor( assert.equal(observerFiredCount, 3, 'observer fired after changing child names'); observerFiredCount = 0; - get(momma, 'children').pushObject(child4); + expectDeprecation(() => { + get(momma, 'children').pushObject(child4); + }, /Usage of Ember.Array methods is deprecated/); await runLoopSettled(); assert.equal(observerFiredCount, 1, 'observer fired after adding a new item'); diff --git a/packages/@ember/-internals/runtime/tests/mixins/array_test.js b/packages/@ember/-internals/runtime/tests/mixins/array_test.js index bf05aa13c7d..f5d1b8a4e68 100644 --- a/packages/@ember/-internals/runtime/tests/mixins/array_test.js +++ b/packages/@ember/-internals/runtime/tests/mixins/array_test.js @@ -7,54 +7,71 @@ import { arrayContentWillChange, } from '@ember/-internals/metal'; import EmberObject, { get, set, computed, observer as emberObserver } from '@ember/object'; -import EmberArray, { A as emberA } from '@ember/array'; -import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; - -/* - Implement a basic fake mutable array. This validates that any non-native - enumerable can impl this API. -*/ -const TestArray = class extends EmberObject.extend(EmberArray) { - _content = null; - - init() { - this._content = this._content || []; - } - - // some methods to modify the array so we can test changes. Note that - // arrays can be modified even if they don't implement MutableArray. The - // MutableArray is just a standard API for mutation but not required. - addObject(obj) { - let idx = this._content.length; - arrayContentWillChange(this, idx, 0, 1); - this._content.push(obj); - arrayContentDidChange(this, idx, 0, 1); - } - - removeFirst() { - arrayContentWillChange(this, 0, 1, 0); - this._content.shift(); - arrayContentDidChange(this, 0, 1, 0); - } - - objectAt(idx) { - return this._content[idx]; - } +import EmberArray from '@ember/array'; +import { + moduleFor, + AbstractTestCase, + runLoopSettled, + expectDeprecation, +} from 'internal-test-helpers'; +import { emberAWithoutDeprecation } from '@ember/routing/-internals'; - get length() { - return this._content.length; - } -}; +let TestArray; moduleFor( 'Ember.Array', class extends AbstractTestCase { + beforeEach() { + expectDeprecation(() => { + /* + Implement a basic fake mutable array. This validates that any non-native + enumerable can impl this API. + */ + TestArray = class extends EmberObject.extend(EmberArray) { + _content = null; + + init() { + this._content = this._content || []; + } + + // some methods to modify the array so we can test changes. Note that + // arrays can be modified even if they don't implement MutableArray. The + // MutableArray is just a standard API for mutation but not required. + addObject(obj) { + let idx = this._content.length; + arrayContentWillChange(this, idx, 0, 1); + this._content.push(obj); + arrayContentDidChange(this, idx, 0, 1); + } + + removeFirst() { + arrayContentWillChange(this, 0, 1, 0); + this._content.shift(); + arrayContentDidChange(this, 0, 1, 0); + } + + objectAt(idx) { + return this._content[idx]; + } + + get length() { + return this._content.length; + } + }; + }, /Usage of EmberArray is deprecated/); + } + ['@test the return value of slice has Ember.Array applied'](assert) { - let x = EmberObject.extend(EmberArray).create({ - length: 0, - }); + let x; + expectDeprecation(() => { + x = EmberObject.extend(EmberArray).create({ + length: 0, + }); + }, /Usage of EmberArray is deprecated/); let y = x.slice(1); - assert.equal(EmberArray.detect(y), true, 'mixin should be applied'); + expectDeprecation(() => { + assert.equal(EmberArray.detect(y), true, 'mixin should be applied'); + }, /Usage of EmberArray is deprecated/); } ['@test slice supports negative index arguments'](assert) { @@ -80,14 +97,7 @@ moduleFor( // CONTENT DID CHANGE // -class DummyArray extends EmberObject.extend(EmberArray) { - length = 0; - objectAt(idx) { - return 'ITEM-' + idx; - } -} - -let obj, observer; +let DummyArray, obj, observer; // .......................................................... // NOTIFY ARRAY OBSERVERS @@ -96,6 +106,16 @@ let obj, observer; moduleFor( 'mixins/array/arrayContent[Will|Did]Change', class extends AbstractTestCase { + beforeEach() { + expectDeprecation(() => { + DummyArray = class extends EmberObject.extend(EmberArray) { + length = 0; + objectAt(idx) { + return 'ITEM-' + idx; + } + }; + }, /Usage of EmberArray is deprecated/); + } async ['@test should notify observers of []'](assert) { obj = DummyArray.extend({ enumerablePropertyDidChange: emberObserver('[]', function () { @@ -345,7 +365,7 @@ moduleFor( let obj = class extends EmberObject { init() { super.init(...arguments); - set(this, 'resources', emberA()); + set(this, 'resources', emberAWithoutDeprecation()); } @computed('resources.@each.common') @@ -354,7 +374,9 @@ moduleFor( } }.create(); - get(obj, 'resources').pushObject(EmberObject.create({ common: 'HI!' })); + expectDeprecation(() => { + get(obj, 'resources').pushObject(EmberObject.create({ common: 'HI!' })); + }, /Usage of Ember.Array methods is deprecated/); assert.equal('HI!', get(obj, 'common')); set(objectAt(get(obj, 'resources'), 0), 'common', 'BYE!'); @@ -370,14 +392,17 @@ moduleFor( init() { this._super(...arguments); // Observer does not fire on init - set(this, 'resources', emberA()); + set(this, 'resources', emberAWithoutDeprecation()); }, commonDidChange: emberObserver('resources.@each.common', () => count++), }).create(); // Observer fires first time when new object is added - get(obj, 'resources').pushObject(EmberObject.create({ common: 'HI!' })); + expectDeprecation(() => { + get(obj, 'resources').pushObject(EmberObject.create({ common: 'HI!' })); + }, /Usage of Ember.Array methods is deprecated/); + await runLoopSettled(); // Observer fires second time when property on an object is changed diff --git a/packages/@ember/-internals/runtime/tests/mixins/mutable_enumerable_test.js b/packages/@ember/-internals/runtime/tests/mixins/mutable_enumerable_test.js index 0a8af297f24..1117f65866f 100644 --- a/packages/@ember/-internals/runtime/tests/mixins/mutable_enumerable_test.js +++ b/packages/@ember/-internals/runtime/tests/mixins/mutable_enumerable_test.js @@ -1,17 +1,22 @@ import MutableEnumerable from '@ember/enumerable/mutable'; -import ArrayProxy from '@ember/array/proxy'; import { A } from '@ember/array'; -import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; +import ArrayProxy from '@ember/array/proxy'; +import { moduleFor, AbstractTestCase, expectDeprecation } from 'internal-test-helpers'; +import { emberAWithoutDeprecation } from '@ember/routing/-internals'; moduleFor( 'MutableEnumerable', class extends AbstractTestCase { ['@test should be mixed into A()'](assert) { - assert.ok(MutableEnumerable.detect(A())); + expectDeprecation(() => { + assert.ok(MutableEnumerable.detect(A())); + }, /Usage of Ember.A is deprecated/); } ['@test should be mixed into ArrayProxy'](assert) { - assert.ok(MutableEnumerable.detect(ArrayProxy.create())); + expectDeprecation(() => { + assert.ok(MutableEnumerable.detect(ArrayProxy.create())); + }, /Usage of ArrayProxy is deprecated/); } } ); diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/addObject-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/addObject-test.js index 383e15d654b..5e018ad6052 100644 --- a/packages/@ember/-internals/runtime/tests/mutable-array/addObject-test.js +++ b/packages/@ember/-internals/runtime/tests/mutable-array/addObject-test.js @@ -1,12 +1,15 @@ import { get } from '@ember/object'; -import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation, runLoopSettled } from 'internal-test-helpers'; import { runArrayTests, newFixture } from '../helpers/array'; class AddObjectTest extends AbstractTestCase { '@test should return receiver'() { let before = newFixture(3); let obj = this.newObject(before); - this.assert.equal(obj.addObject(before[1]), obj, 'should return receiver'); + + expectDeprecation(() => { + this.assert.equal(obj.addObject(before[1]), obj, 'should return receiver'); + }, /Usage of Ember.Array methods is deprecated/); } async '@test [A,B].addObject(C) => [A,B,C] + notify'() { @@ -16,9 +19,13 @@ class AddObjectTest extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.addObject(item); + expectDeprecation(() => { + obj.addObject(item); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -53,9 +60,13 @@ class AddObjectTest extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.addObject(item); // note: item in set + expectDeprecation(() => { + obj.addObject(item); // note: item in set + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/clear-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/clear-test.js index 3b9726d8b00..c2423883adf 100644 --- a/packages/@ember/-internals/runtime/tests/mutable-array/clear-test.js +++ b/packages/@ember/-internals/runtime/tests/mutable-array/clear-test.js @@ -1,5 +1,5 @@ import { get } from '@ember/object'; -import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation, runLoopSettled } from 'internal-test-helpers'; import { runArrayTests, newFixture } from '../helpers/array'; class ClearTests extends AbstractTestCase { @@ -12,9 +12,13 @@ class ClearTests extends AbstractTestCase { // flush observers await runLoopSettled(); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - this.assert.equal(obj.clear(), obj, 'return self'); + expectDeprecation(() => { + this.assert.equal(obj.clear(), obj, 'return self'); + }, /Usage of Ember.Array methods is deprecated/); this.assert.deepEqual(this.toArray(obj), after, 'post item results'); this.assert.equal(get(obj, 'length'), after.length, 'length'); @@ -43,9 +47,13 @@ class ClearTests extends AbstractTestCase { after = []; obj = this.newObject(before); observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - this.assert.equal(obj.clear(), obj, 'return self'); + expectDeprecation(() => { + this.assert.equal(obj.clear(), obj, 'return self'); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/insertAt-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/insertAt-test.js index 1182812c2ab..f749740c07b 100644 --- a/packages/@ember/-internals/runtime/tests/mutable-array/insertAt-test.js +++ b/packages/@ember/-internals/runtime/tests/mutable-array/insertAt-test.js @@ -1,5 +1,10 @@ import { get } from '@ember/object'; -import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { + AbstractTestCase, + expectDeprecation, + ignoreDeprecation, + runLoopSettled, +} from 'internal-test-helpers'; import { runArrayTests, newFixture } from '../helpers/array'; class InsertAtTests extends AbstractTestCase { @@ -8,9 +13,13 @@ class InsertAtTests extends AbstractTestCase { let obj = this.newObject([]); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.insertAt(0, after[0]); + expectDeprecation(() => { + obj.insertAt(0, after[0]); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -46,7 +55,9 @@ class InsertAtTests extends AbstractTestCase { '@test [].insertAt(200,X) => OUT_OF_RANGE_EXCEPTION exception'() { let obj = this.newObject([]); let item = newFixture(1)[0]; - expectAssertion(() => obj.insertAt(200, item), /`insertAt` index provided is out of range/); + expectDeprecation(() => { + expectAssertion(() => obj.insertAt(200, item), /`insertAt` index provided is out of range/); + }, /Usage of Ember.Array methods is deprecated/); } async '@test [A].insertAt(0, X) => [X,A] + notify'() { @@ -56,9 +67,13 @@ class InsertAtTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.insertAt(0, item); + expectDeprecation(() => { + obj.insertAt(0, item); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -91,9 +106,13 @@ class InsertAtTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.insertAt(1, item); + expectDeprecation(() => { + obj.insertAt(1, item); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -123,7 +142,9 @@ class InsertAtTests extends AbstractTestCase { let obj = this.newObject(newFixture(1)); let that = this; - this.assert.throws(() => obj.insertAt(200, that.newFixture(1)[0]), Error); + ignoreDeprecation(() => { + this.assert.throws(() => obj.insertAt(200, that.newFixture(1)[0]), Error); + }); } async '@test [A,B,C].insertAt(0,X) => [X,A,B,C] + notify'() { @@ -133,9 +154,13 @@ class InsertAtTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.insertAt(0, item); + expectDeprecation(() => { + obj.insertAt(0, item); + }, /Usage of Ember.Array methods is deprecated/); await runLoopSettled(); @@ -174,11 +199,15 @@ class InsertAtTests extends AbstractTestCase { return objectAt.call(obj, ix); }; - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); objectAtCalls.splice(0, objectAtCalls.length); - obj.insertAt(1, item); + expectDeprecation(() => { + obj.insertAt(1, item); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -213,9 +242,13 @@ class InsertAtTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.insertAt(3, item); + expectDeprecation(() => { + obj.insertAt(3, item); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -242,4 +275,4 @@ class InsertAtTests extends AbstractTestCase { } } -runArrayTests('instertAt', InsertAtTests, 'MutableArray', 'NativeArray', 'ArrayProxy'); +runArrayTests('insertAt', InsertAtTests, 'MutableArray', 'NativeArray', 'ArrayProxy'); diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/popObject-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/popObject-test.js index c5d463b6ff0..fa4db4c4ceb 100644 --- a/packages/@ember/-internals/runtime/tests/mutable-array/popObject-test.js +++ b/packages/@ember/-internals/runtime/tests/mutable-array/popObject-test.js @@ -1,5 +1,5 @@ import { get } from '@ember/object'; -import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation, runLoopSettled } from 'internal-test-helpers'; import { runArrayTests, newFixture } from '../helpers/array'; class PopObjectTests extends AbstractTestCase { @@ -7,9 +7,13 @@ class PopObjectTests extends AbstractTestCase { let obj = this.newObject([]); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - this.assert.equal(obj.popObject(), undefined, 'popObject results'); + expectDeprecation(() => { + this.assert.equal(obj.popObject(), undefined, 'popObject results'); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -39,9 +43,14 @@ class PopObjectTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - let ret = obj.popObject(); + let ret; + expectDeprecation(() => { + ret = obj.popObject(); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -73,9 +82,14 @@ class PopObjectTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - let ret = obj.popObject(); + let ret; + expectDeprecation(() => { + ret = obj.popObject(); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/pushObject-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/pushObject-test.js index b8b55554ff0..34883753db6 100644 --- a/packages/@ember/-internals/runtime/tests/mutable-array/pushObject-test.js +++ b/packages/@ember/-internals/runtime/tests/mutable-array/pushObject-test.js @@ -1,5 +1,5 @@ import { get } from '@ember/object'; -import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation, runLoopSettled } from 'internal-test-helpers'; import { runArrayTests, newFixture } from '../helpers/array'; class PushObjectTests extends AbstractTestCase { @@ -7,7 +7,9 @@ class PushObjectTests extends AbstractTestCase { let exp = newFixture(1)[0]; let obj = this.newObject([]); - this.assert.equal(obj.pushObject(exp), exp, 'should return pushed object'); + expectDeprecation(() => { + this.assert.equal(obj.pushObject(exp), exp, 'should return pushed object'); + }, /Usage of Ember.Array methods is deprecated/); } async '@test [].pushObject(X) => [X] + notify'() { @@ -16,9 +18,13 @@ class PushObjectTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.pushObject(after[0]); + expectDeprecation(() => { + obj.pushObject(after[0]); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -50,9 +56,13 @@ class PushObjectTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.pushObject(item); + expectDeprecation(() => { + obj.pushObject(item); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -85,9 +95,13 @@ class PushObjectTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.pushObject(item); + expectDeprecation(() => { + obj.pushObject(item); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/pushObjects-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/pushObjects-test.js index 55a67b4139e..7ce59659023 100644 --- a/packages/@ember/-internals/runtime/tests/mutable-array/pushObjects-test.js +++ b/packages/@ember/-internals/runtime/tests/mutable-array/pushObjects-test.js @@ -1,11 +1,13 @@ -import { AbstractTestCase } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation } from 'internal-test-helpers'; import { runArrayTests } from '../helpers/array'; class PushObjectsTests extends AbstractTestCase { '@test should raise exception if not Ember.Enumerable is passed to pushObjects'() { let obj = this.newObject([]); - expectAssertion(() => obj.pushObjects('string')); + expectDeprecation(() => { + expectAssertion(() => obj.pushObjects('string')); + }, /Usage of Ember.Array methods is deprecated/); } } diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/removeAt-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/removeAt-test.js index fedf2195d05..c222ffa84da 100644 --- a/packages/@ember/-internals/runtime/tests/mutable-array/removeAt-test.js +++ b/packages/@ember/-internals/runtime/tests/mutable-array/removeAt-test.js @@ -1,4 +1,4 @@ -import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation, runLoopSettled } from 'internal-test-helpers'; import { runArrayTests, newFixture } from '../helpers/array'; import { removeAt } from '@ember/array'; import { get } from '@ember/object'; @@ -10,7 +10,9 @@ class RemoveAtTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); this.assert.equal(removeAt(obj, 0), obj, 'return self'); @@ -48,7 +50,9 @@ class RemoveAtTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); this.assert.equal(removeAt(obj, 0), obj, 'return self'); @@ -82,7 +86,9 @@ class RemoveAtTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); this.assert.equal(removeAt(obj, 1), obj, 'return self'); @@ -116,7 +122,9 @@ class RemoveAtTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); this.assert.equal(removeAt(obj, 1), obj, 'return self'); @@ -150,7 +158,9 @@ class RemoveAtTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); this.assert.equal(removeAt(obj, 1, 2), obj, 'return self'); @@ -185,9 +195,14 @@ class RemoveAtTests extends AbstractTestCase { after = [before[0], before[3]]; obj = this.newObject(before); observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ - this.assert.equal(obj.removeAt(1, 2), obj, 'return self'); + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); + + expectDeprecation(() => { + this.assert.equal(obj.removeAt(1, 2), obj, 'return self'); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/removeObject-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/removeObject-test.js index 86e828e2b09..f007e2b7b1c 100644 --- a/packages/@ember/-internals/runtime/tests/mutable-array/removeObject-test.js +++ b/packages/@ember/-internals/runtime/tests/mutable-array/removeObject-test.js @@ -1,5 +1,5 @@ import { get } from '@ember/object'; -import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation, runLoopSettled } from 'internal-test-helpers'; import { runArrayTests, newFixture } from '../helpers/array'; class RemoveObjectTests extends AbstractTestCase { @@ -7,7 +7,9 @@ class RemoveObjectTests extends AbstractTestCase { let before = newFixture(3); let obj = this.newObject(before); - this.assert.equal(obj.removeObject(before[1]), obj, 'should return receiver'); + expectDeprecation(() => { + this.assert.equal(obj.removeObject(before[1]), obj, 'should return receiver'); + }, /Usage of Ember.Array methods is deprecated/); obj.destroy(); } @@ -18,9 +20,13 @@ class RemoveObjectTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.removeObject(before[1]); + expectDeprecation(() => { + obj.removeObject(before[1]); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -55,9 +61,13 @@ class RemoveObjectTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.removeObject(item); // note: item not in set + expectDeprecation(() => { + obj.removeObject(item); // note: item not in set + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/removeObjects-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/removeObjects-test.js index 13d71267781..1c11b93a78f 100644 --- a/packages/@ember/-internals/runtime/tests/mutable-array/removeObjects-test.js +++ b/packages/@ember/-internals/runtime/tests/mutable-array/removeObjects-test.js @@ -1,7 +1,11 @@ import { get } from '@ember/object'; -import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { + AbstractTestCase, + runLoopSettled, + emberAWithoutDeprecation as emberA, + expectDeprecation, +} from 'internal-test-helpers'; import { runArrayTests, newFixture, newObjectsFixture } from '../helpers/array'; -import { A as emberA } from '@ember/array'; import { destroy } from '@glimmer/destroyable'; class RemoveObjectsTests extends AbstractTestCase { @@ -9,7 +13,9 @@ class RemoveObjectsTests extends AbstractTestCase { let before = emberA(newFixture(3)); let obj = before; - this.assert.equal(obj.removeObjects(before[1]), obj, 'should return receiver'); + expectDeprecation(() => { + this.assert.equal(obj.removeObjects(before[1]), obj, 'should return receiver'); + }, /Usage of Ember.Array methods is deprecated/); } async '@test [A,B,C].removeObjects([B]) => [A,C] + notify'() { @@ -18,9 +24,13 @@ class RemoveObjectsTests extends AbstractTestCase { let obj = before; let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); // Prime the cache + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); // Prime the cache + }, /Usage of Ember.Array methods is deprecated/); - obj.removeObjects([before[1]]); + expectDeprecation(() => { + obj.removeObjects([before[1]]); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -53,9 +63,13 @@ class RemoveObjectsTests extends AbstractTestCase { let obj = before; let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); // Prime the cache + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); // Prime the cache + }, /Usage of Ember.Array methods is deprecated/); - obj.removeObjects([before[1]]); + expectDeprecation(() => { + obj.removeObjects([before[1]]); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -88,9 +102,13 @@ class RemoveObjectsTests extends AbstractTestCase { let obj = before; let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); // Prime the cache + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); // Prime the cache + }, /Usage of Ember.Array methods is deprecated/); - obj.removeObjects([before[0], before[1]]); + expectDeprecation(() => { + obj.removeObjects([before[0], before[1]]); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -119,9 +137,13 @@ class RemoveObjectsTests extends AbstractTestCase { let obj = before; let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); // Prime the cache + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); // Prime the cache + }, /Usage of Ember.Array methods is deprecated/); - obj.removeObjects([before[0], before[1]]); + expectDeprecation(() => { + obj.removeObjects([before[0], before[1]]); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -150,9 +172,13 @@ class RemoveObjectsTests extends AbstractTestCase { let obj = before; let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); // Prime the cache + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); // Prime the cache + }, /Usage of Ember.Array methods is deprecated/); - obj.removeObjects([before[0], before[1], before[2]]); + expectDeprecation(() => { + obj.removeObjects([before[0], before[1], before[2]]); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -177,9 +203,13 @@ class RemoveObjectsTests extends AbstractTestCase { let obj = before; let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); // Prime the cache + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); // Prime the cache + }, /Usage of Ember.Array methods is deprecated/); - obj.removeObjects(before); + expectDeprecation(() => { + obj.removeObjects(before); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -205,9 +235,13 @@ class RemoveObjectsTests extends AbstractTestCase { let obj = before; let observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); // Prime the cache + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); // Prime the cache + }, /Usage of Ember.Array methods is deprecated/); - obj.removeObjects([item]); // Note: item not in set + expectDeprecation(() => { + obj.removeObjects([item]); // Note: item not in set + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/replace-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/replace-test.js index 7b72f9591ba..5d3cdd554c2 100644 --- a/packages/@ember/-internals/runtime/tests/mutable-array/replace-test.js +++ b/packages/@ember/-internals/runtime/tests/mutable-array/replace-test.js @@ -1,4 +1,4 @@ -import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation, runLoopSettled } from 'internal-test-helpers'; import { runArrayTests, newFixture } from '../helpers/array'; class ReplaceTests extends AbstractTestCase { @@ -7,9 +7,13 @@ class ReplaceTests extends AbstractTestCase { let obj = this.newObject([]); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.replace(0, 0, exp); + expectDeprecation(() => { + obj.replace(0, 0, exp); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -43,7 +47,9 @@ class ReplaceTests extends AbstractTestCase { }; observer = this.newObserver(obj, 'firstObject', 'lastObject'); - obj.replace(0, 0, exp); + expectDeprecation(() => { + obj.replace(0, 0, exp); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -75,9 +81,13 @@ class ReplaceTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.replace(1, 2, replace); + expectDeprecation(() => { + obj.replace(1, 2, replace); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -110,9 +120,13 @@ class ReplaceTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.replace(1, 2, replace); + expectDeprecation(() => { + obj.replace(1, 2, replace); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -145,9 +159,13 @@ class ReplaceTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.replace(1, 0, replace); + expectDeprecation(() => { + obj.replace(1, 0, replace); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -179,9 +197,13 @@ class ReplaceTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.replace(2, 2); + expectDeprecation(() => { + obj.replace(2, 2); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -213,9 +235,13 @@ class ReplaceTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.replace(-1, 1); + expectDeprecation(() => { + obj.replace(-1, 1); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -246,7 +272,9 @@ class ReplaceTests extends AbstractTestCase { let observer = this.newObserver(obj).observeArray(obj); let item = newFixture(1)[0]; - obj.replace(2, 2, [item]); + expectDeprecation(() => { + obj.replace(2, 2, [item]); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/reverseObjects-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/reverseObjects-test.js index ee16585bd5b..1eb4fd5622b 100644 --- a/packages/@ember/-internals/runtime/tests/mutable-array/reverseObjects-test.js +++ b/packages/@ember/-internals/runtime/tests/mutable-array/reverseObjects-test.js @@ -1,4 +1,4 @@ -import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation, runLoopSettled } from 'internal-test-helpers'; import { runArrayTests, newFixture } from '../helpers/array'; import { get } from '@ember/object'; @@ -9,9 +9,13 @@ class ReverseObjectsTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - this.assert.equal(obj.reverseObjects(), obj, 'return self'); + expectDeprecation(() => { + this.assert.equal(obj.reverseObjects(), obj, 'return self'); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/setObjects-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/setObjects-test.js index 91385a04737..5a841bf42d7 100644 --- a/packages/@ember/-internals/runtime/tests/mutable-array/setObjects-test.js +++ b/packages/@ember/-internals/runtime/tests/mutable-array/setObjects-test.js @@ -1,4 +1,4 @@ -import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation, runLoopSettled } from 'internal-test-helpers'; import { runArrayTests, newFixture } from '../helpers/array'; import { get } from '@ember/object'; @@ -9,9 +9,13 @@ class SetObjectsTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - this.assert.equal(obj.setObjects(after), obj, 'return self'); + expectDeprecation(() => { + this.assert.equal(obj.setObjects(after), obj, 'return self'); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -42,9 +46,13 @@ class SetObjectsTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - this.assert.equal(obj.setObjects(after), obj, 'return self'); + expectDeprecation(() => { + this.assert.equal(obj.setObjects(after), obj, 'return self'); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/shiftObject-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/shiftObject-test.js index 39217ecae91..95c891a7e1b 100644 --- a/packages/@ember/-internals/runtime/tests/mutable-array/shiftObject-test.js +++ b/packages/@ember/-internals/runtime/tests/mutable-array/shiftObject-test.js @@ -1,4 +1,4 @@ -import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation, runLoopSettled } from 'internal-test-helpers'; import { runArrayTests, newFixture } from '../helpers/array'; import { get } from '@ember/object'; @@ -9,9 +9,13 @@ class ShiftObjectTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - this.assert.equal(obj.shiftObject(), undefined); + expectDeprecation(() => { + this.assert.equal(obj.shiftObject(), undefined); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -55,9 +59,13 @@ class ShiftObjectTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - this.assert.equal(obj.shiftObject(), before[0], 'should return object'); + expectDeprecation(() => { + this.assert.equal(obj.shiftObject(), before[0], 'should return object'); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -88,9 +96,13 @@ class ShiftObjectTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - this.assert.equal(obj.shiftObject(), before[0], 'should return object'); + expectDeprecation(() => { + this.assert.equal(obj.shiftObject(), before[0], 'should return object'); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/unshiftObject-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/unshiftObject-test.js index 2e94387e2b5..bfd64fc68d4 100644 --- a/packages/@ember/-internals/runtime/tests/mutable-array/unshiftObject-test.js +++ b/packages/@ember/-internals/runtime/tests/mutable-array/unshiftObject-test.js @@ -1,4 +1,4 @@ -import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation, runLoopSettled } from 'internal-test-helpers'; import { get } from '@ember/object'; import { runArrayTests, newFixture } from '../helpers/array'; @@ -7,7 +7,9 @@ class UnshiftObjectTests extends AbstractTestCase { let obj = this.newObject([]); let item = newFixture(1)[0]; - this.assert.equal(obj.unshiftObject(item), item, 'should return unshifted object'); + expectDeprecation(() => { + this.assert.equal(obj.unshiftObject(item), item, 'should return unshifted object'); + }, /Usage of Ember.Array methods is deprecated/); } async '@test [].unshiftObject(X) => [X] + notify'() { @@ -17,9 +19,13 @@ class UnshiftObjectTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.unshiftObject(item); + expectDeprecation(() => { + obj.unshiftObject(item); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -51,9 +57,13 @@ class UnshiftObjectTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.unshiftObject(item); + expectDeprecation(() => { + obj.unshiftObject(item); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -86,9 +96,13 @@ class UnshiftObjectTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.unshiftObject(item); + expectDeprecation(() => { + obj.unshiftObject(item); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); diff --git a/packages/@ember/-internals/runtime/tests/mutable-array/unshiftObjects-test.js b/packages/@ember/-internals/runtime/tests/mutable-array/unshiftObjects-test.js index 44b92473ad3..4de9f258243 100644 --- a/packages/@ember/-internals/runtime/tests/mutable-array/unshiftObjects-test.js +++ b/packages/@ember/-internals/runtime/tests/mutable-array/unshiftObjects-test.js @@ -1,4 +1,4 @@ -import { AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { AbstractTestCase, expectDeprecation, runLoopSettled } from 'internal-test-helpers'; import { get } from '@ember/object'; import { runArrayTests, newFixture } from '../helpers/array'; @@ -7,7 +7,13 @@ class UnshiftObjectsTests extends AbstractTestCase { let obj = this.newObject([]); let items = newFixture(3); - this.assert.equal(obj.unshiftObjects(items), obj, 'should return receiver'); + expectDeprecation(() => { + obj.unshiftObjects(items); + }, /Usage of Ember.Array methods is deprecated/); + + expectDeprecation(() => { + this.assert.equal(obj.unshiftObjects(items), obj, 'should return receiver'); + }, /Usage of Ember.Array methods is deprecated/); } async '@test [].unshiftObjects([A,B,C]) => [A,B,C] + notify'() { @@ -16,9 +22,13 @@ class UnshiftObjectsTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.unshiftObjects(items); + expectDeprecation(() => { + obj.unshiftObjects(items); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -50,9 +60,13 @@ class UnshiftObjectsTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.unshiftObjects(items); + expectDeprecation(() => { + obj.unshiftObjects(items); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); @@ -85,9 +99,13 @@ class UnshiftObjectsTests extends AbstractTestCase { let obj = this.newObject(before); let observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); - obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + expectDeprecation(() => { + obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ + }, /Usage of Ember.Array methods is deprecated/); - obj.unshiftObjects(items); + expectDeprecation(() => { + obj.unshiftObjects(items); + }, /Usage of Ember.Array methods is deprecated/); // flush observers await runLoopSettled(); diff --git a/packages/@ember/-internals/runtime/tests/system/array_proxy/arranged_content_test.js b/packages/@ember/-internals/runtime/tests/system/array_proxy/arranged_content_test.js index fbdfefb902f..3e6981927d5 100644 --- a/packages/@ember/-internals/runtime/tests/system/array_proxy/arranged_content_test.js +++ b/packages/@ember/-internals/runtime/tests/system/array_proxy/arranged_content_test.js @@ -2,8 +2,12 @@ import { run } from '@ember/runloop'; import { objectAt } from '@ember/-internals/metal'; import { computed } from '@ember/object'; import ArrayProxy from '@ember/array/proxy'; -import { A as emberA } from '@ember/array'; -import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; +import { + moduleFor, + AbstractTestCase, + expectDeprecation, + emberAWithoutDeprecation as emberA, +} from 'internal-test-helpers'; let array; @@ -12,28 +16,30 @@ moduleFor( class extends AbstractTestCase { beforeEach() { run(() => { - array = class extends ArrayProxy { - @computed('content.[]') - get arrangedContent() { - let content = this.get('content'); - return ( - content && - emberA( - content.slice().sort((a, b) => { - if (a == null) { - a = -1; - } - if (b == null) { - b = -1; - } - return b - a; - }) - ) - ); - } - }.create({ - content: emberA([1, 2, 4, 5]), - }); + expectDeprecation(() => { + array = class extends ArrayProxy { + @computed('content.[]') + get arrangedContent() { + let content = this.get('content'); + return ( + content && + emberA( + content.slice().sort((a, b) => { + if (a == null) { + a = -1; + } + if (b == null) { + b = -1; + } + return b - a; + }) + ) + ); + } + }.create({ + content: emberA([1, 2, 4, 5]), + }); + }, /Usage of ArrayProxy is deprecated/); }); } @@ -44,7 +50,9 @@ moduleFor( ['@test compact - returns arrangedContent without nulls and undefined'](assert) { run(() => array.set('content', emberA([1, 3, null, 2, undefined]))); - assert.deepEqual(array.compact(), [3, 2, 1]); + expectDeprecation(() => { + assert.deepEqual(array.compact(), [3, 2, 1]); + }, /Usage of Ember.Array methods is deprecated/); } ['@test indexOf - returns index of object in arrangedContent'](assert) { @@ -52,7 +60,9 @@ moduleFor( } ['@test lastIndexOf - returns last index of object in arrangedContent'](assert) { - array.get('content').pushObject(4); + expectDeprecation(() => { + array.get('content').pushObject(4); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(array.lastIndexOf(4), 2, 'returns last arranged index'); } @@ -66,7 +76,13 @@ moduleFor( } ['@test objectsAt - returns objects at indices in arrangedContent'](assert) { - assert.deepEqual(array.objectsAt([0, 2, 4]), [5, 2, undefined], 'returns objects at indices'); + expectDeprecation(() => { + assert.deepEqual( + array.objectsAt([0, 2, 4]), + [5, 2, undefined], + 'returns objects at indices' + ); + }, /Usage of Ember.Array methods is deprecated/); } ['@test replace - mutating an arranged ArrayProxy is not allowed']() { @@ -89,15 +105,21 @@ moduleFor( } ['@test without - returns arrangedContent without object'](assert) { - assert.deepEqual(array.without(2), [5, 4, 1], 'returns arranged without object'); + expectDeprecation(() => { + assert.deepEqual(array.without(2), [5, 4, 1], 'returns arranged without object'); + }, /Usage of Ember.Array methods is deprecated/); } ['@test lastObject - returns last arranged object'](assert) { - assert.equal(array.get('lastObject'), 1, 'returns last arranged object'); + expectDeprecation(() => { + assert.equal(array.get('lastObject'), 1, 'returns last arranged object'); + }, /Usage of Ember.Array methods is deprecated/); } ['@test firstObject - returns first arranged object'](assert) { - assert.equal(array.get('firstObject'), 5, 'returns first arranged object'); + expectDeprecation(() => { + assert.equal(array.get('firstObject'), 5, 'returns first arranged object'); + }, /Usage of Ember.Array methods is deprecated/); } } ); @@ -107,9 +129,11 @@ moduleFor( class extends AbstractTestCase { beforeEach() { run(function () { - array = ArrayProxy.create({ - content: emberA([1, 2, 4, 5]), - }); + expectDeprecation(() => { + array = ArrayProxy.create({ + content: emberA([1, 2, 4, 5]), + }); + }, /Usage of ArrayProxy is deprecated/); }); } @@ -120,22 +144,28 @@ moduleFor( } ['@test insertAt - inserts object at specified index'](assert) { - run(function () { - array.insertAt(2, 3); - }); + expectDeprecation(() => { + run(function () { + array.insertAt(2, 3); + }); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual(array.get('content'), [1, 2, 3, 4, 5]); } ['@test replace - does a standard array replace'](assert) { run(function () { - array.replace(1, 2, [3]); + expectDeprecation(() => { + array.replace(1, 2, [3]); + }, /Usage of Ember.Array methods is deprecated/); }); assert.deepEqual(array.get('content'), [1, 3, 5]); } ['@test reverseObjects - reverses content'](assert) { run(function () { - array.reverseObjects(); + expectDeprecation(() => { + array.reverseObjects(); + }, /Usage of Ember.Array methods is deprecated/); }); assert.deepEqual(array.get('content'), [5, 4, 2, 1]); } @@ -147,33 +177,35 @@ moduleFor( class extends AbstractTestCase { beforeEach() { run(function () { - array = class extends ArrayProxy { - @computed('content.[]') - get arrangedContent() { - let content = this.get('content'); - return ( - content && - emberA( - content.slice().sort(function (a, b) { - if (a == null) { - a = -1; - } - if (b == null) { - b = -1; - } - return b - a; - }) - ) - ); - } - - objectAtContent(idx) { - let obj = objectAt(this.get('arrangedContent'), idx); - return obj && obj.toString(); - } - }.create({ - content: emberA([1, 2, 4, 5]), - }); + expectDeprecation(() => { + array = class extends ArrayProxy { + @computed('content.[]') + get arrangedContent() { + let content = this.get('content'); + return ( + content && + emberA( + content.slice().sort(function (a, b) { + if (a == null) { + a = -1; + } + if (b == null) { + b = -1; + } + return b - a; + }) + ) + ); + } + + objectAtContent(idx) { + let obj = objectAt(this.get('arrangedContent'), idx); + return obj && obj.toString(); + } + }.create({ + content: emberA([1, 2, 4, 5]), + }); + }, /Usage of ArrayProxy is deprecated/); }); } @@ -188,7 +220,9 @@ moduleFor( } ['@test lastIndexOf - returns last index of object in arrangedContent'](assert) { - array.get('content').pushObject(4); + expectDeprecation(() => { + array.get('content').pushObject(4); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(array.lastIndexOf('4'), 2, 'returns last arranged index'); } @@ -202,11 +236,13 @@ moduleFor( } ['@test objectsAt - returns objects at indices in arrangedContent'](assert) { - assert.deepEqual( - array.objectsAt([0, 2, 4]), - ['5', '2', undefined], - 'returns objects at indices' - ); + expectDeprecation(() => { + assert.deepEqual( + array.objectsAt([0, 2, 4]), + ['5', '2', undefined], + 'returns objects at indices' + ); + }, /Usage of Ember.Array methods is deprecated/); } ['@test slice - returns a slice of the arrangedContent'](assert) { @@ -218,15 +254,21 @@ moduleFor( } ['@test without - returns arrangedContent without object'](assert) { - assert.deepEqual(array.without('2'), ['5', '4', '1'], 'returns arranged without object'); + expectDeprecation(() => { + assert.deepEqual(array.without('2'), ['5', '4', '1'], 'returns arranged without object'); + }, /Usage of Ember.Array methods is deprecated/); } ['@test lastObject - returns last arranged object'](assert) { - assert.equal(array.get('lastObject'), '1', 'returns last arranged object'); + expectDeprecation(() => { + assert.equal(array.get('lastObject'), '1', 'returns last arranged object'); + }, /Usage of Ember.Array methods is deprecated/); } ['@test firstObject - returns first arranged object'](assert) { - assert.equal(array.get('firstObject'), '5', 'returns first arranged object'); + expectDeprecation(() => { + assert.equal(array.get('firstObject'), '5', 'returns first arranged object'); + }, /Usage of Ember.Array methods is deprecated/); } } ); @@ -236,14 +278,16 @@ moduleFor( class extends AbstractTestCase { beforeEach() { run(function () { - array = class extends ArrayProxy { - objectAtContent(idx) { - let obj = objectAt(this.get('arrangedContent'), idx); - return obj && obj.toString(); - } - }.create({ - content: emberA([1, 2, 4, 5]), - }); + expectDeprecation(() => { + array = class extends ArrayProxy { + objectAtContent(idx) { + let obj = objectAt(this.get('arrangedContent'), idx); + return obj && obj.toString(); + } + }.create({ + content: emberA([1, 2, 4, 5]), + }); + }, /Usage of ArrayProxy is deprecated/); }); } @@ -254,23 +298,33 @@ moduleFor( } ['@test popObject - removes last object in arrangedContent'](assert) { - let popped = array.popObject(); + let popped; + expectDeprecation(() => { + popped = array.popObject(); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(popped, '5', 'returns last object'); assert.deepEqual(array.toArray(), ['1', '2', '4'], 'removes from content'); } ['@test removeObject - removes object from content'](assert) { - array.removeObject('2'); + expectDeprecation(() => { + array.removeObject('2'); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual(array.toArray(), ['1', '4', '5']); } ['@test removeObjects - removes objects from content'](assert) { - array.removeObjects(['2', '4', '6']); + expectDeprecation(() => { + array.removeObjects(['2', '4', '6']); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual(array.toArray(), ['1', '5']); } ['@test shiftObject - removes from start of arrangedContent'](assert) { - let shifted = array.shiftObject(); + let shifted; + expectDeprecation(() => { + shifted = array.shiftObject(); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(shifted, '1', 'returns first object'); assert.deepEqual(array.toArray(), ['2', '4', '5'], 'removes object from content'); } diff --git a/packages/@ember/-internals/runtime/tests/system/array_proxy/content_change_test.js b/packages/@ember/-internals/runtime/tests/system/array_proxy/content_change_test.js index e3af74e2cfb..d2b66a04e6c 100644 --- a/packages/@ember/-internals/runtime/tests/system/array_proxy/content_change_test.js +++ b/packages/@ember/-internals/runtime/tests/system/array_proxy/content_change_test.js @@ -2,15 +2,24 @@ import { run } from '@ember/runloop'; import { changeProperties } from '@ember/-internals/metal'; import { set } from '@ember/object'; import ArrayProxy from '@ember/array/proxy'; -import { A as emberA } from '@ember/array'; -import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; +import { + moduleFor, + AbstractTestCase, + expectDeprecation, + emberAWithoutDeprecation as emberA, +} from 'internal-test-helpers'; moduleFor( 'ArrayProxy - content change', class extends AbstractTestCase { ["@test The ArrayProxy doesn't explode when assigned a destroyed object"](assert) { - let proxy1 = ArrayProxy.create(); - let proxy2 = ArrayProxy.create(); + let proxy1; + let proxy2; + + expectDeprecation(() => { + proxy1 = ArrayProxy.create(); + proxy2 = ArrayProxy.create(); + }, /Usage of ArrayProxy is deprecated/); run(() => proxy1.destroy()); @@ -20,7 +29,10 @@ moduleFor( } ['@test should update if content changes while change events are deferred'](assert) { - let proxy = ArrayProxy.create(); + let proxy; + expectDeprecation(() => { + proxy = ArrayProxy.create(); + }, /Usage of ArrayProxy is deprecated/); assert.deepEqual(proxy.toArray(), []); @@ -33,51 +45,69 @@ moduleFor( ['@test objectAt recomputes the object cache correctly'](assert) { let indexes = []; - let proxy = class extends ArrayProxy { - objectAtContent(index) { - indexes.push(index); - return this.content[index]; - } - }.create({ - content: emberA([1, 2, 3, 4, 5]), - }); + let proxy; + expectDeprecation(() => { + proxy = class extends ArrayProxy { + objectAtContent(index) { + indexes.push(index); + return this.content[index]; + } + }.create({ + content: emberA([1, 2, 3, 4, 5]), + }); + }, /Usage of ArrayProxy is deprecated/); assert.deepEqual(indexes, []); - assert.deepEqual(proxy.objectAt(0), 1); + expectDeprecation(() => { + assert.deepEqual(proxy.objectAt(0), 1); + }, /Usage of Ember.Array methods is deprecated/); + assert.deepEqual(indexes, [0, 1, 2, 3, 4]); indexes.length = 0; proxy.set('content', emberA([1, 2, 3])); - assert.deepEqual(proxy.objectAt(0), 1); + expectDeprecation(() => { + assert.deepEqual(proxy.objectAt(0), 1); + }, /Usage of Ember.Array methods is deprecated/); + assert.deepEqual(indexes, [0, 1, 2]); indexes.length = 0; - proxy.content.replace(2, 0, [4, 5]); - assert.deepEqual(proxy.objectAt(0), 1); - assert.deepEqual(proxy.objectAt(1), 2); - assert.deepEqual(indexes, []); - assert.deepEqual(proxy.objectAt(2), 4); - assert.deepEqual(indexes, [2, 3, 4]); + expectDeprecation(() => { + proxy.content.replace(2, 0, [4, 5]); + }, /Usage of Ember.Array methods is deprecated/); + expectDeprecation(() => { + assert.deepEqual(proxy.objectAt(0), 1); + assert.deepEqual(proxy.objectAt(1), 2); + assert.deepEqual(indexes, []); + assert.deepEqual(proxy.objectAt(2), 4); + assert.deepEqual(indexes, [2, 3, 4]); + }, /Usage of Ember.Array methods is deprecated/); } ['@test negative indexes are handled correctly'](assert) { let indexes = []; - let proxy = class extends ArrayProxy { - objectAtContent(index) { - indexes.push(index); - return this.content[index]; - } - }.create({ - content: emberA([1, 2, 3, 4, 5]), - }); + let proxy; + expectDeprecation(() => { + proxy = class extends ArrayProxy { + objectAtContent(index) { + indexes.push(index); + return this.content[index]; + } + }.create({ + content: emberA([1, 2, 3, 4, 5]), + }); + }, /Usage of ArrayProxy is deprecated/); assert.deepEqual(proxy.toArray(), [1, 2, 3, 4, 5]); indexes.length = 0; - proxy.content.replace(-1, 0, [7]); - proxy.content.replace(-2, 0, [6]); + expectDeprecation(() => { + proxy.content.replace(-1, 0, [7]); + proxy.content.replace(-2, 0, [6]); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual(proxy.toArray(), [1, 2, 3, 4, 6, 7, 5]); assert.deepEqual(indexes, [4, 5, 6]); diff --git a/packages/@ember/-internals/runtime/tests/system/array_proxy/length_test.js b/packages/@ember/-internals/runtime/tests/system/array_proxy/length_test.js index 41ce4894f9e..91982dd9a6c 100644 --- a/packages/@ember/-internals/runtime/tests/system/array_proxy/length_test.js +++ b/packages/@ember/-internals/runtime/tests/system/array_proxy/length_test.js @@ -1,8 +1,14 @@ import ArrayProxy from '@ember/array/proxy'; import EmberObject, { observer } from '@ember/object'; import { oneWay as reads, not } from '@ember/object/computed'; -import { A as a } from '@ember/array'; -import { moduleFor, AbstractTestCase, runTask, runLoopSettled } from 'internal-test-helpers'; +import { + moduleFor, + AbstractTestCase, + runTask, + runLoopSettled, + expectDeprecation, + emberAWithoutDeprecation as a, +} from 'internal-test-helpers'; import { set, get } from '@ember/object'; import { createCache, getValue } from '@glimmer/validator'; @@ -10,9 +16,12 @@ moduleFor( 'Ember.ArrayProxy - content change (length)', class extends AbstractTestCase { ['@test should update length for null content'](assert) { - let proxy = ArrayProxy.create({ - content: a([1, 2, 3]), - }); + let proxy; + expectDeprecation(() => { + proxy = ArrayProxy.create({ + content: a([1, 2, 3]), + }); + }, /Usage of ArrayProxy is deprecated/); assert.equal(proxy.get('length'), 3, 'precond - length is 3'); @@ -24,12 +33,15 @@ moduleFor( ['@test should update length for null content when there is a computed property watching length']( assert ) { - let proxy = class extends ArrayProxy { - @not('length') - isEmpty; - }.create({ - content: a([1, 2, 3]), - }); + let proxy; + expectDeprecation(() => { + proxy = class extends ArrayProxy { + @not('length') + isEmpty; + }.create({ + content: a([1, 2, 3]), + }); + }, /Usage of ArrayProxy is deprecated/); assert.equal(proxy.get('length'), 3, 'precond - length is 3'); @@ -45,14 +57,17 @@ moduleFor( ['@test getting length does not recompute the object cache'](assert) { let indexes = []; - let proxy = class extends ArrayProxy { - objectAtContent(index) { - indexes.push(index); - return this.content[index]; - } - }.create({ - content: a([1, 2, 3, 4, 5]), - }); + let proxy; + expectDeprecation(() => { + proxy = class extends ArrayProxy { + objectAtContent(index) { + indexes.push(index); + return this.content[index]; + } + }.create({ + content: a([1, 2, 3, 4, 5]), + }); + }, /Usage of ArrayProxy is deprecated/); assert.equal(get(proxy, 'length'), 5); assert.deepEqual(indexes, []); @@ -63,14 +78,18 @@ moduleFor( assert.deepEqual(indexes, []); indexes.length = 0; - proxy.content.replace(1, 0, [1, 2, 3]); + expectDeprecation(() => { + proxy.content.replace(1, 0, [1, 2, 3]); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(get(proxy, 'length'), 6); assert.deepEqual(indexes, []); } '@test accessing length after content set to null'(assert) { - let obj = ArrayProxy.create({ content: ['foo', 'bar'] }); - + let obj; + expectDeprecation(() => { + obj = ArrayProxy.create({ content: ['foo', 'bar'] }); + }, /Usage of ArrayProxy is deprecated/); assert.equal(obj.length, 2, 'precond'); set(obj, 'content', null); @@ -80,14 +99,17 @@ moduleFor( } '@test accessing length after content set to null in willDestroy'(assert) { - let obj = class extends ArrayProxy { - willDestroy() { - this.set('content', null); - this._super(...arguments); - } - }.create({ - content: ['foo', 'bar'], - }); + let obj; + expectDeprecation(() => { + obj = class extends ArrayProxy { + willDestroy() { + this.set('content', null); + this._super(...arguments); + } + }.create({ + content: ['foo', 'bar'], + }); + }, /Usage of ArrayProxy is deprecated/); assert.equal(obj.length, 2, 'precond'); @@ -98,8 +120,10 @@ moduleFor( } '@test setting length to 0'(assert) { - let obj = ArrayProxy.create({ content: ['foo', 'bar'] }); - + let obj; + expectDeprecation(() => { + obj = ArrayProxy.create({ content: ['foo', 'bar'] }); + }, /Usage of ArrayProxy is deprecated/); assert.equal(obj.length, 2, 'precond'); set(obj, 'length', 0); @@ -109,8 +133,10 @@ moduleFor( } '@test setting length to smaller value'(assert) { - let obj = ArrayProxy.create({ content: ['foo', 'bar'] }); - + let obj; + expectDeprecation(() => { + obj = ArrayProxy.create({ content: ['foo', 'bar'] }); + }, /Usage of ArrayProxy is deprecated/); assert.equal(obj.length, 2, 'precond'); set(obj, 'length', 1); @@ -120,8 +146,10 @@ moduleFor( } '@test setting length to larger value'(assert) { - let obj = ArrayProxy.create({ content: ['foo', 'bar'] }); - + let obj; + expectDeprecation(() => { + obj = ArrayProxy.create({ content: ['foo', 'bar'] }); + }, /Usage of ArrayProxy is deprecated/); assert.equal(obj.length, 2, 'precond'); set(obj, 'length', 3); @@ -131,8 +159,10 @@ moduleFor( } '@test setting length after content set to null'(assert) { - let obj = ArrayProxy.create({ content: ['foo', 'bar'] }); - + let obj; + expectDeprecation(() => { + obj = ArrayProxy.create({ content: ['foo', 'bar'] }); + }, /Usage of ArrayProxy is deprecated/); assert.equal(obj.length, 2, 'precond'); set(obj, 'content', null); @@ -143,7 +173,10 @@ moduleFor( } '@test setting length to greater than zero'(assert) { - let obj = ArrayProxy.create({ content: ['foo', 'bar'] }); + let obj; + expectDeprecation(() => { + obj = ArrayProxy.create({ content: ['foo', 'bar'] }); + }, /Usage of ArrayProxy is deprecated/); assert.equal(obj.length, 2, 'precond'); @@ -172,12 +205,14 @@ moduleFor( // bootstrap aliases obj.length; - obj.set( - 'model', - ArrayProxy.create({ - content: a(['red', 'yellow', 'blue']), - }) - ); + expectDeprecation(() => { + obj.set( + 'model', + ArrayProxy.create({ + content: a(['red', 'yellow', 'blue']), + }) + ); + }, /Usage of ArrayProxy is deprecated/); await runLoopSettled(); @@ -191,7 +226,10 @@ moduleFor( assert.equal(dCalled, 1, 'expected observer `colors.[]` to be called ONCE'); assert.equal(eCalled, 1, 'expected observer `colors.content.[]` to be called ONCE'); - obj.get('colors').pushObjects(['green', 'red']); + expectDeprecation(() => { + obj.get('colors').pushObjects(['green', 'red']); + }, /Usage of Ember.Array methods is deprecated/); + await runLoopSettled(); assert.equal(obj.get('colors.content.length'), 5); @@ -208,19 +246,26 @@ moduleFor( } async ['@test array proxy length is reactive when accessed normally'](assert) { - let proxy = ArrayProxy.create({ - content: a([1, 2, 3]), + let proxy; + expectDeprecation(() => { + proxy = ArrayProxy.create({ + content: a([1, 2, 3]), + }); }); let lengthCache = createCache(() => proxy.length); assert.equal(getValue(lengthCache), 3, 'length is correct'); - proxy.pushObject(4); + expectDeprecation(() => { + proxy.pushObject(4); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(getValue(lengthCache), 4, 'length is correct'); - proxy.removeObject(1); + expectDeprecation(() => { + proxy.removeObject(1); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(getValue(lengthCache), 3, 'length is correct'); @@ -230,19 +275,26 @@ moduleFor( } async ['@test array proxy length is reactive when accessed using get'](assert) { - let proxy = ArrayProxy.create({ - content: a([1, 2, 3]), - }); + let proxy; + expectDeprecation(() => { + proxy = ArrayProxy.create({ + content: a([1, 2, 3]), + }); + }, /Usage of ArrayProxy is deprecated/); let lengthCache = createCache(() => get(proxy, 'length')); assert.equal(getValue(lengthCache), 3, 'length is correct'); - proxy.pushObject(4); + expectDeprecation(() => { + proxy.pushObject(4); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(getValue(lengthCache), 4, 'length is correct'); - proxy.removeObject(1); + expectDeprecation(() => { + proxy.removeObject(1); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(getValue(lengthCache), 3, 'length is correct'); diff --git a/packages/@ember/-internals/runtime/tests/system/array_proxy/watching_and_listening_test.js b/packages/@ember/-internals/runtime/tests/system/array_proxy/watching_and_listening_test.js index 8ff87454e2b..097bcb582f8 100644 --- a/packages/@ember/-internals/runtime/tests/system/array_proxy/watching_and_listening_test.js +++ b/packages/@ember/-internals/runtime/tests/system/array_proxy/watching_and_listening_test.js @@ -1,7 +1,11 @@ import { peekMeta } from '@ember/-internals/meta'; import ArrayProxy from '@ember/array/proxy'; -import { A } from '@ember/array'; -import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; +import { + moduleFor, + emberAWithoutDeprecation as A, + AbstractTestCase, + expectDeprecation, +} from 'internal-test-helpers'; function sortedListenersFor(obj, eventName) { let listeners = peekMeta(obj).matchingListeners(eventName) || []; @@ -18,7 +22,10 @@ moduleFor( class extends AbstractTestCase { [`@test setting 'content' adds listeners correctly`](assert) { let content = A(); - let proxy = ArrayProxy.create(); + let proxy; + expectDeprecation(() => { + proxy = ArrayProxy.create(); + }, /Usage of ArrayProxy is deprecated/); assert.deepEqual(sortedListenersFor(content, '@array:before'), []); assert.deepEqual(sortedListenersFor(content, '@array:change'), []); @@ -36,7 +43,10 @@ moduleFor( [`@test changing 'content' adds and removes listeners correctly`](assert) { let content1 = A(); let content2 = A(); - let proxy = ArrayProxy.create({ content: content1 }); + let proxy; + expectDeprecation(() => { + proxy = ArrayProxy.create({ content: content1 }); + }, /Usage of ArrayProxy is deprecated/); assert.deepEqual(sortedListenersFor(content1, '@array:before'), []); assert.deepEqual(sortedListenersFor(content1, '@array:change'), []); diff --git a/packages/@ember/-internals/runtime/tests/system/native_array/a_test.js b/packages/@ember/-internals/runtime/tests/system/native_array/a_test.js index e9b72d65d1a..64dc85e406a 100644 --- a/packages/@ember/-internals/runtime/tests/system/native_array/a_test.js +++ b/packages/@ember/-internals/runtime/tests/system/native_array/a_test.js @@ -1,25 +1,55 @@ import EmberArray from '@ember/array'; import { A } from '@ember/array'; -import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; +import { + moduleFor, + emberAWithoutDeprecation, + AbstractTestCase, + expectDeprecation, +} from 'internal-test-helpers'; moduleFor( 'Ember.A', class extends AbstractTestCase { ['@test Ember.A'](assert) { - assert.deepEqual(A([1, 2]), [1, 2], 'array values were not be modified'); - assert.deepEqual(A(), [], 'returned an array with no arguments'); - assert.deepEqual(A(null), [], 'returned an array with a null argument'); - assert.ok(EmberArray.detect(A()), 'returned an ember array'); - assert.ok(EmberArray.detect(A([1, 2])), 'returned an ember array'); + assert.deepEqual( + emberAWithoutDeprecation([1, 2]), + [1, 2], + 'array values were not be modified' + ); + assert.deepEqual(emberAWithoutDeprecation(), [], 'returned an array with no arguments'); + assert.deepEqual( + emberAWithoutDeprecation(null), + [], + 'returned an array with a null argument' + ); + expectDeprecation(() => { + assert.ok(EmberArray.detect(emberAWithoutDeprecation()), 'returned an ember array'); + assert.ok(EmberArray.detect(emberAWithoutDeprecation([1, 2])), 'returned an ember array'); + }, /Usage of EmberArray is deprecated/); + } + + ['@test Ember.A deprecation'](assert) { + expectDeprecation(() => { + assert.deepEqual(A([1, 2]), [1, 2], 'array values were not be modified'); + assert.deepEqual(A(), [], 'returned an array with no arguments'); + assert.deepEqual(A(null), [], 'returned an array with a null argument'); + }, /Usage of Ember.A is deprecated/); } ['@test new Ember.A'](assert) { expectAssertion(() => { - assert.deepEqual(new A([1, 2]), [1, 2], 'array values were not be modified'); - assert.deepEqual(new A(), [], 'returned an array with no arguments'); - assert.deepEqual(new A(null), [], 'returned an array with a null argument'); - assert.ok(EmberArray.detect(new A()), 'returned an ember array'); - assert.ok(EmberArray.detect(new A([1, 2])), 'returned an ember array'); + expectDeprecation(() => { + assert.deepEqual(new A([1, 2]), [1, 2], 'array values were not be modified'); + assert.deepEqual(new A(), [], 'returned an array with no arguments'); + assert.deepEqual(new A(null), [], 'returned an array with a null argument'); + }, /Usage of Ember.A is deprecated/); + expectDeprecation(() => { + assert.ok(EmberArray.detect(new emberAWithoutDeprecation()), 'returned an ember array'); + assert.ok( + EmberArray.detect(new emberAWithoutDeprecation([1, 2])), + 'returned an ember array' + ); + }, /Usage of EmberArray is deprecated/); }); } } diff --git a/packages/@ember/-internals/runtime/tests/system/native_array/replace_test.js b/packages/@ember/-internals/runtime/tests/system/native_array/replace_test.js index dbcdba82f50..30dc3bf7238 100644 --- a/packages/@ember/-internals/runtime/tests/system/native_array/replace_test.js +++ b/packages/@ember/-internals/runtime/tests/system/native_array/replace_test.js @@ -1,17 +1,25 @@ -import { A } from '@ember/array'; -import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; +import { + moduleFor, + emberAWithoutDeprecation as A, + AbstractTestCase, + expectDeprecation, +} from 'internal-test-helpers'; moduleFor( 'NativeArray.replace', class extends AbstractTestCase { ['@test raises assertion if third argument is not an array']() { expectAssertion(function () { - A([1, 2, 3]).replace(1, 1, ''); + expectDeprecation(() => { + A([1, 2, 3]).replace(1, 1, ''); + }, /Usage of Ember.Array methods is deprecated/); }, 'The third argument to replace needs to be an array.'); } ['@test it does not raise an assertion if third parameter is not passed'](assert) { - assert.deepEqual(A([1, 2, 3]).replace(1, 2), A([1]), 'no assertion raised'); + expectDeprecation(() => { + assert.deepEqual(A([1, 2, 3]).replace(1, 2), A([1]), 'no assertion raised'); + }, /Usage of Ember.Array methods is deprecated/); } } ); diff --git a/packages/@ember/-internals/utils/lib/mixin-deprecation.ts b/packages/@ember/-internals/utils/lib/mixin-deprecation.ts new file mode 100644 index 00000000000..adf0f084c46 --- /dev/null +++ b/packages/@ember/-internals/utils/lib/mixin-deprecation.ts @@ -0,0 +1,42 @@ +import type { DeprecationOptions } from '@ember/debug'; +import type Mixin from '@ember/object/mixin'; + +/** @internal */ +export const DEPRECATION = Symbol('DEPRECATION'); + +/** @internal */ +export function setDeprecation( + mixin: Mixin, + value: { message: string; options: DeprecationOptions } | null +) { + mixin[DEPRECATION] = value; +} + +let deprecationsEnabled = true; + +export function findDeprecation( + mixin: Mixin +): { message: string; options: DeprecationOptions } | null { + if (!deprecationsEnabled) { + return null; + } + if (mixin[DEPRECATION]) { + return mixin[DEPRECATION]; + } + for (let childMixin of mixin.mixins ?? []) { + let deprecation = findDeprecation(childMixin); + if (deprecation) { + return deprecation; + } + } + return null; +} + +export function disableDeprecations(callback: () => T): T { + try { + deprecationsEnabled = false; + return callback(); + } finally { + deprecationsEnabled = true; + } +} diff --git a/packages/@ember/array/-internals.ts b/packages/@ember/array/-internals.ts index e25e288d641..04df00e8ab6 100644 --- a/packages/@ember/array/-internals.ts +++ b/packages/@ember/array/-internals.ts @@ -9,3 +9,18 @@ export function setEmberArray(obj: object) { export function isEmberArray(obj: unknown): obj is EmberArrayLike { return EMBER_ARRAYS.has(obj as object); } + +let _deprecationsAreDisabled = false; +export function disableDeprecations(callback: () => T): T { + const original = _deprecationsAreDisabled; + _deprecationsAreDisabled = true; + try { + return callback(); + } finally { + _deprecationsAreDisabled = original; + } +} + +export function deprecationsAreDisabled(): boolean { + return _deprecationsAreDisabled; +} diff --git a/packages/@ember/array/index.ts b/packages/@ember/array/index.ts index bdff2a18e4b..5e815d5b2cd 100644 --- a/packages/@ember/array/index.ts +++ b/packages/@ember/array/index.ts @@ -13,14 +13,24 @@ import { } from '@ember/-internals/metal'; import { get, set } from '@ember/object'; import Mixin from '@ember/object/mixin'; -import { assert } from '@ember/debug'; +import { assert, deprecate } from '@ember/debug'; import Enumerable from '@ember/enumerable'; import MutableEnumerable from '@ember/enumerable/mutable'; import { compare, typeOf } from '@ember/utils'; import Observable from '@ember/object/observable'; import type { MethodNamesOf, MethodParams, MethodReturns } from '@ember/-internals/utility-types'; import type { ComputedPropertyCallback } from '@ember/-internals/metal'; -import { isEmberArray, setEmberArray } from '@ember/array/-internals'; +import { + deprecationsAreDisabled, + disableDeprecations, + isEmberArray, + setEmberArray, +} from '@ember/array/-internals'; +import { + disableDeprecations as disableMixinDeprecations, + setDeprecation, +} from '@ember/-internals/utils/lib/mixin-deprecation'; +import ArrayProxy from './proxy'; export { default as makeArray } from './make'; @@ -178,7 +188,7 @@ export function isArray(obj: unknown): obj is ArrayLike | EmberArray EmberArray.detect(obj))) { return true; } @@ -206,6 +216,12 @@ function nonEnumerableComputed(callback: ComputedPropertyCallback) { } function mapBy(this: EmberArray, key: string) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); return this.map((next) => get(next, key)); } @@ -1202,6 +1218,12 @@ const EmberArray = Mixin.create(Enumerable, { }, objectsAt(indexes: number[]) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); return indexes.map((idx) => objectAt(this, idx)); }, @@ -1216,16 +1238,28 @@ const EmberArray = Mixin.create(Enumerable, { }), firstObject: nonEnumerableComputed(function () { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); return objectAt(this, 0); }).readOnly(), lastObject: nonEnumerableComputed(function () { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); return objectAt(this, this.length - 1); }).readOnly(), // Add any extra methods to EmberArray that are native to the built-in Array. slice(beginIndex = 0, endIndex?: number) { - let ret = A(); + let ret = disableDeprecations(() => A()); let length = this.length; if (beginIndex < 0) { @@ -1288,6 +1322,12 @@ const EmberArray = Mixin.create(Enumerable, { getEach: mapBy, setEach(key: string, value: unknown) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); return this.forEach((item: object) => set(item, key, value)); }, @@ -1298,7 +1338,7 @@ const EmberArray = Mixin.create(Enumerable, { ) { assert('`map` expects a function as first argument.', typeof callback === 'function'); - let ret = A(); + let ret = disableDeprecations(() => A()); this.forEach((x, idx, i) => (ret[idx] = callback.call(target, x, idx, i))); @@ -1314,7 +1354,7 @@ const EmberArray = Mixin.create(Enumerable, { ) { assert('`filter` expects a function as first argument.', typeof callback === 'function'); - let ret = A(); + let ret = disableDeprecations(() => A()); this.forEach((x, idx, i) => { if (callback.call(target, x, idx, i)) { @@ -1330,6 +1370,12 @@ const EmberArray = Mixin.create(Enumerable, { callback: (item: T, index: number, arr: EmberArray) => unknown, target = null ) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); assert('`reject` expects a function as first argument.', typeof callback === 'function'); return this.filter(function () { // @ts-expect-error TS doesn't like us using arguments like this @@ -1338,11 +1384,23 @@ const EmberArray = Mixin.create(Enumerable, { }, filterBy() { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); // @ts-expect-error TS doesn't like the ...arguments spread here. return this.filter(iter(...arguments)); }, rejectBy() { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); // @ts-expect-error TS doesn't like the ...arguments spread here. return this.reject(iter(...arguments)); }, @@ -1353,6 +1411,12 @@ const EmberArray = Mixin.create(Enumerable, { }, findBy() { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); // @ts-expect-error TS doesn't like the ...arguments spread here. let callback = iter(...arguments); return find(this, callback); @@ -1364,17 +1428,35 @@ const EmberArray = Mixin.create(Enumerable, { }, isEvery() { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); // @ts-expect-error TS doesn't like the ...arguments spread here. let callback = iter(...arguments); return every(this, callback); }, any(callback: (item: T, index: number, arr: EmberArray) => unknown, target = null) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); assert('`any` expects a function as first argument.', typeof callback === 'function'); return any(this, callback, target); }, isAny() { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); // @ts-expect-error TS doesn't like us using arguments like this let callback = iter(...arguments); return any(this, callback); @@ -1398,19 +1480,33 @@ const EmberArray = Mixin.create(Enumerable, { }, invoke(this: EmberArray, methodName: string, ...args: unknown[]) { - let ret = A(); - - // SAFETY: This is not entirely safe and the code will not work with Ember proxies - this.forEach((item: T) => ret.push((item as any)[methodName]?.(...args))); + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); + let ret; + disableDeprecations(() => { + ret = A(); + // SAFETY: This is not entirely safe and the code will not work with Ember proxies + this.forEach((item: T) => ret.push((item as any)[methodName]?.(...args))); + }); return ret; }, toArray(this: EmberArray) { - return this.map((item: T) => item); + return disableDeprecations(() => this.map((item: T) => item)); }, compact(this: EmberArray) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); return this.filter((value: T) => value != null); }, @@ -1419,6 +1515,12 @@ const EmberArray = Mixin.create(Enumerable, { }, sortBy(this: EmberArray) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); let sortKeys = arguments; return this.toArray().sort((a: T, b: T) => { @@ -1438,14 +1540,33 @@ const EmberArray = Mixin.create(Enumerable, { }, uniq() { - return uniqBy(this); + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); + + return disableDeprecations(() => uniqBy(this)); }, uniqBy(key: string) { - return uniqBy(this, key); + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); + return disableDeprecations(() => uniqBy(this, key)); }, without(this: EmberArray, value: T) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); if (!this.includes(value)) { return this; // nothing to do } @@ -1456,6 +1577,16 @@ const EmberArray = Mixin.create(Enumerable, { }, }); +setDeprecation(EmberArray, { + message: 'Usage of EmberArray is deprecated', + options: { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }, +}); + /** This mixin defines the API for modifying array-like objects. These methods can be applied only to a collection that keeps its items in an ordered set. @@ -1734,6 +1865,12 @@ interface MutableArray extends EmberArray, MutableEnumerable { } const MutableArray = Mixin.create(EmberArray, MutableEnumerable, { clear() { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); let len = this.length; if (len === 0) { return this; @@ -1744,24 +1881,54 @@ const MutableArray = Mixin.create(EmberArray, MutableEnumerable, { }, insertAt(idx: number, object: unknown) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); insertAt(this, idx, object); return this; }, removeAt(start: number, len?: number) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); return removeAt(this, start, len); }, pushObject(this: MutableArray, obj: T) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); return insertAt(this, this.length, obj); }, pushObjects(this: MutableArray, objects: T[]) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); this.replace(this.length, 0, objects); return this; }, popObject() { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); let len = this.length; if (len === 0) { return null; @@ -1773,6 +1940,12 @@ const MutableArray = Mixin.create(EmberArray, MutableEnumerable, { }, shiftObject() { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); if (this.length === 0) { return null; } @@ -1783,15 +1956,33 @@ const MutableArray = Mixin.create(EmberArray, MutableEnumerable, { }, unshiftObject(this: MutableArray, obj: T) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); return insertAt(this, 0, obj); }, unshiftObjects(this: MutableArray, objects: T[]) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); this.replace(0, 0, objects); return this; }, reverseObjects() { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); let len = this.length; if (len === 0) { return this; @@ -1803,6 +1994,12 @@ const MutableArray = Mixin.create(EmberArray, MutableEnumerable, { }, setObjects(this: MutableArray, objects: T[]) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); if (objects.length === 0) { return this.clear(); } @@ -1813,6 +2010,12 @@ const MutableArray = Mixin.create(EmberArray, MutableEnumerable, { }, removeObject(this: MutableArray, obj: T) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); let loc = this.length || 0; while (--loc >= 0) { let curObject = objectAt(this, loc); @@ -1825,6 +2028,12 @@ const MutableArray = Mixin.create(EmberArray, MutableEnumerable, { }, removeObjects(this: MutableArray, objects: T[]) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); beginPropertyChanges(); for (let i = objects.length - 1; i >= 0; i--) { // SAFETY: Due to the loop structure we know this will always exist. @@ -1835,6 +2044,12 @@ const MutableArray = Mixin.create(EmberArray, MutableEnumerable, { }, addObject(this: MutableArray, obj: T) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); let included = this.includes(obj); if (!included) { @@ -1845,6 +2060,12 @@ const MutableArray = Mixin.create(EmberArray, MutableEnumerable, { }, addObjects(this: MutableArray, objects: T[]) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); beginPropertyChanges(); objects.forEach((obj) => this.addObject(obj)); endPropertyChanges(); @@ -1852,6 +2073,16 @@ const MutableArray = Mixin.create(EmberArray, MutableEnumerable, { }, }); +setDeprecation(MutableArray, { + message: 'Usage of MutableArray is deprecated', + options: { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }, +}); + /** Creates an `Ember.NativeArray` from an Array-like object. Does not modify the original object's contents. @@ -2064,11 +2295,23 @@ interface NativeArray extends Array, Observable, MutableArrayWithoutNative let NativeArray = Mixin.create(MutableArray, Observable, { objectAt(idx: number) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); return this[idx]; }, // primitive for array support. replace(start: number, deleteCount: number, items = EMPTY_ARRAY) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); assert('The third argument to replace needs to be an array.', Array.isArray(items)); replaceInNativeArray(this, start, deleteCount, items); @@ -2088,9 +2331,26 @@ NativeArray.keys().forEach((methodName) => { NativeArray = NativeArray.without(...ignore); +setDeprecation(NativeArray, { + message: 'Usage of EmberArray is deprecated', + options: { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }, +}); + let A: (arr?: Array) => NativeArray; A = function (this: unknown, arr?: Array) { + deprecate('Usage of Ember.A is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); + assert( 'You cannot create an Ember Array with `new A()`, please update to calling A as a function: `A()`', !(this instanceof A) @@ -2101,7 +2361,7 @@ A = function (this: unknown, arr?: Array) { return arr as unknown as NativeArray; } else { // SAFETY: This will return an NativeArray but TS can't infer that. - return NativeArray.apply(arr ?? []) as NativeArray; + return disableMixinDeprecations(() => NativeArray.apply(arr ?? []) as NativeArray); } }; diff --git a/packages/@ember/array/proxy.ts b/packages/@ember/array/proxy.ts index ff72f1990ac..942f1974865 100644 --- a/packages/@ember/array/proxy.ts +++ b/packages/@ember/array/proxy.ts @@ -19,7 +19,7 @@ import { isObject } from '@ember/-internals/utils'; import EmberObject from '@ember/object'; import EmberArray, { type NativeArray } from '@ember/array'; import MutableArray from '@ember/array/mutable'; -import { assert } from '@ember/debug'; +import { assert, deprecate } from '@ember/debug'; import { setCustomTagFor } from '@glimmer/manager'; import { combine, @@ -30,6 +30,8 @@ import { type Tag, type Revision, } from '@glimmer/validator'; +import { disableDeprecations } from '@ember/-internals/utils/lib/mixin-deprecation'; +import { deprecationsAreDisabled } from './-internals'; function isMutable(obj: T[] | EmberArray): obj is T[] | MutableArray { return Array.isArray(obj) || typeof (obj as MutableArray).replace === 'function'; @@ -201,6 +203,15 @@ class ArrayProxy extends EmberObject implements PropertyDidChange { _arrTag: Tag | null = null; init(props: object | undefined) { + // This is not used internally, so instead of warning every time one of the methods is used, + // we can just warn when it is created. + deprecate('Usage of ArrayProxy is deprecated.', false, { + for: 'ember-source', + id: 'array-proxy', + since: { available: '6.8.0' }, + until: '7.0.0', + }); + super.init(props); setCustomTagFor(this, customTagForArrayProxy); @@ -231,6 +242,12 @@ class ArrayProxy extends EmberObject implements PropertyDidChange { 'Mutating an arranged ArrayProxy is not allowed', get(this, 'arrangedContent') === get(this, 'content') ); + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); this.replaceContent(idx, amt, objects); } @@ -243,6 +260,13 @@ class ArrayProxy extends EmberObject implements PropertyDidChange { // Overriding objectAt is not supported. objectAt(idx: number) { + deprecate('Usage of Ember.Array methods is deprecated', deprecationsAreDisabled(), { + for: 'ember-source', + id: 'ember-array', + since: { available: '6.8.0' }, + until: '7.0.0', + }); + this._revalidate(); if (this._objects === null) { @@ -407,8 +431,10 @@ class ArrayProxy extends EmberObject implements PropertyDidChange { } } -ArrayProxy.reopen(MutableArray, { - arrangedContent: alias('content'), +disableDeprecations(() => { + ArrayProxy.reopen(MutableArray, { + arrangedContent: alias('content'), + }); }); export default ArrayProxy; diff --git a/packages/@ember/enumerable/tests/enumerable_test.js b/packages/@ember/enumerable/tests/enumerable_test.js index caf4e226f29..da5b690fd36 100644 --- a/packages/@ember/enumerable/tests/enumerable_test.js +++ b/packages/@ember/enumerable/tests/enumerable_test.js @@ -1,17 +1,21 @@ import Enumerable from '@ember/enumerable'; import ArrayProxy from '@ember/array/proxy'; import { A } from '@ember/array'; -import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; +import { moduleFor, AbstractTestCase, expectDeprecation } from 'internal-test-helpers'; moduleFor( 'Enumerable', class extends AbstractTestCase { ['@test should be mixed into A()'](assert) { - assert.ok(Enumerable.detect(A())); + expectDeprecation(() => { + assert.ok(Enumerable.detect(A())); + }, /Usage of Ember.A is deprecated/); } ['@test should be mixed into ArrayProxy'](assert) { - assert.ok(Enumerable.detect(ArrayProxy.create())); + expectDeprecation(() => { + assert.ok(Enumerable.detect(ArrayProxy.create())); + }, /Usage of ArrayProxy is deprecated/); } } ); diff --git a/packages/@ember/object/core.ts b/packages/@ember/object/core.ts index 106169e3ef8..742099e4bd5 100644 --- a/packages/@ember/object/core.ts +++ b/packages/@ember/object/core.ts @@ -24,6 +24,7 @@ import { assert } from '@ember/debug'; import { DEBUG } from '@glimmer/env'; import { destroy, isDestroying, isDestroyed, registerDestructor } from '@glimmer/destroyable'; import { OWNER } from '@glimmer/owner'; +import { disableDeprecations } from '@ember/-internals/utils/lib/mixin-deprecation'; type EmberClassConstructor = new (owner?: Owner) => T; @@ -1038,7 +1039,7 @@ class CoreObject { // If the prototype mixin exists, apply it. In the case of native classes, // it will not exist (unless the class has been reopened). if (prototypeMixinMap.has(this)) { - this.PrototypeMixin.apply(p); + disableDeprecations(() => this.PrototypeMixin.apply(p)); } } return p; diff --git a/packages/@ember/object/lib/computed/reduce_computed_macros.ts b/packages/@ember/object/lib/computed/reduce_computed_macros.ts index 525c9611746..3dc6f9c76dd 100644 --- a/packages/@ember/object/lib/computed/reduce_computed_macros.ts +++ b/packages/@ember/object/lib/computed/reduce_computed_macros.ts @@ -2,15 +2,28 @@ @module @ember/object */ import { DEBUG } from '@glimmer/env'; -import { assert } from '@ember/debug'; +import { assert, deprecate } from '@ember/debug'; import { autoComputed, isElementDescriptor } from '@ember/-internals/metal'; import { computed, get } from '@ember/object'; import { compare } from '@ember/utils'; import EmberArray, { A as emberA, uniqBy as uniqByArray } from '@ember/array'; import type { NativeArray } from '@ember/array'; +import { disableDeprecations as disableArrayDeprecations } from '@ember/array/-internals'; +import { disableDeprecations as disableMixinDeprecations } from '@ember/-internals/utils/lib/mixin-deprecation'; + +let deprecationsAreDisabled = false; +function disableDeprecations(callback: () => T): T { + const original = deprecationsAreDisabled; + deprecationsAreDisabled = true; + try { + return callback(); + } finally { + deprecationsAreDisabled = original; + } +} function isNativeOrEmberArray(obj: unknown): obj is unknown[] | EmberArray { - return Array.isArray(obj) || EmberArray.detect(obj); + return Array.isArray(obj) || disableMixinDeprecations(() => EmberArray.detect(obj)); } function reduceMacro( @@ -48,12 +61,14 @@ function arrayMacro( } return computed(dependentKey, ...additionalDependentKeys, function () { - let value = get(this, propertyName); - if (isNativeOrEmberArray(value)) { - return emberA(callback.call(this, value)); - } else { - return emberA(); - } + return disableArrayDeprecations(() => { + let value = get(this, propertyName); + if (isNativeOrEmberArray(value)) { + return emberA(callback.call(this, value)); + } else { + return emberA(); + } + }); }).readOnly() as PropertyDecorator; } @@ -69,7 +84,7 @@ function multiArrayMacro( let dependentKeys = _dependentKeys.map((key) => `${key}.[]`); return computed(...dependentKeys, function () { - return emberA(callback.call(this, _dependentKeys)); + return disableArrayDeprecations(() => emberA(callback.call(this, _dependentKeys))); }).readOnly() as PropertyDecorator; } @@ -102,6 +117,13 @@ function multiArrayMacro( @public */ export function sum(dependentKey: string) { + deprecate('The @sum decorator is deprecated. Use TrackedArray with native getters.', false, { + for: 'ember-source', + id: 'ember-object.sum-deprecated', + since: { available: '7.9.0' }, + until: '8.0.0', + }); + assert( 'You attempted to use @sum as a decorator directly, but it requires a `dependentKey` parameter', !isElementDescriptor(Array.prototype.slice.call(arguments)) @@ -166,6 +188,13 @@ export function sum(dependentKey: string) { @public */ export function max(dependentKey: string) { + deprecate('The @max decorator is deprecated. Use TrackedArray with native getters.', false, { + for: 'ember-source', + id: 'ember-object.max-deprecated', + since: { available: '7.9.0' }, + until: '8.0.0', + }); + assert( 'You attempted to use @max as a decorator directly, but it requires a `dependentKey` parameter', !isElementDescriptor(Array.prototype.slice.call(arguments)) @@ -229,6 +258,13 @@ export function max(dependentKey: string) { @public */ export function min(dependentKey: string) { + deprecate('The @min decorator is deprecated. Use TrackedArray with native getters.', false, { + for: 'ember-source', + id: 'ember-object.min-deprecated', + since: { available: '7.9.0' }, + until: '8.0.0', + }); + assert( 'You attempted to use @min as a decorator directly, but it requires a `dependentKey` parameter', !isElementDescriptor(Array.prototype.slice.call(arguments)) @@ -326,6 +362,17 @@ export function map( additionalDependentKeysOrCallback: string[] | ((value: unknown, index: number) => unknown), callback?: (value: unknown, index: number) => unknown ): PropertyDecorator { + deprecate( + 'The @map decorator is deprecated. Use TrackedArray with native getters.', + deprecationsAreDisabled, + { + for: 'ember-source', + id: 'ember-object.map-deprecated', + since: { available: '7.9.0' }, + until: '8.0.0', + } + ); + assert( 'You attempted to use @map as a decorator directly, but it requires atleast `dependentKey` and `callback` parameters', !isElementDescriptor(Array.prototype.slice.call(arguments)) @@ -410,6 +457,13 @@ export function map( @public */ export function mapBy(dependentKey: string, propertyKey: string) { + deprecate('The @mapBy decorator is deprecated. Use TrackedArray with native getters.', false, { + for: 'ember-source', + id: 'ember-object.mapBy-deprecated', + since: { available: '7.9.0' }, + until: '8.0.0', + }); + assert( 'You attempted to use @mapBy as a decorator directly, but it requires `dependentKey` and `propertyKey` parameters', !isElementDescriptor(Array.prototype.slice.call(arguments)) @@ -425,7 +479,9 @@ export function mapBy(dependentKey: string, propertyKey: string) { !/[[\]{}]/g.test(dependentKey) ); - return map(`${dependentKey}.@each.${propertyKey}`, (item) => get(item, propertyKey)); + return disableDeprecations(() => + map(`${dependentKey}.@each.${propertyKey}`, (item) => get(item, propertyKey)) + ); } /** @@ -552,6 +608,17 @@ export function filter( | ((value: unknown, index: number, array: unknown[] | EmberArray) => unknown), callback?: (value: unknown, index: number, array: unknown[] | EmberArray) => unknown ): PropertyDecorator { + deprecate( + 'The @filter decorator is deprecated. Use TrackedArray with native getters.', + deprecationsAreDisabled, + { + for: 'ember-source', + id: 'ember-object.filter-deprecated', + since: { available: '7.9.0' }, + until: '8.0.0', + } + ); + assert( 'You attempted to use @filter as a decorator directly, but it requires atleast `dependentKey` and `callback` parameters', !isElementDescriptor(Array.prototype.slice.call(arguments)) @@ -634,6 +701,13 @@ export function filter( @public */ export function filterBy(dependentKey: string, propertyKey: string, value?: unknown) { + deprecate('The @filterBy decorator is deprecated. Use TrackedArray with native getters.', false, { + for: 'ember-source', + id: 'ember-object.filterBy-deprecated', + since: { available: '7.9.0' }, + until: '8.0.0', + }); + assert( 'You attempted to use @filterBy as a decorator directly, but it requires atleast `dependentKey` and `propertyKey` parameters', !isElementDescriptor(Array.prototype.slice.call(arguments)) @@ -644,14 +718,14 @@ export function filterBy(dependentKey: string, propertyKey: string, value?: unkn !/[[\]{}]/g.test(dependentKey) ); - let callback; + let callback: (item: unknown) => unknown; if (arguments.length === 2) { callback = (item: unknown) => get(item, propertyKey); } else { callback = (item: unknown) => get(item, propertyKey) === value; } - return filter(`${dependentKey}.@each.${propertyKey}`, callback); + return disableDeprecations(() => filter(`${dependentKey}.@each.${propertyKey}`, callback)); } /** @@ -694,8 +768,19 @@ export function uniq( dependentKey: string, ...additionalDependentKeys: string[] ): PropertyDecorator { + deprecate( + 'The @uniq/@union decorator is deprecated. Use TrackedArray with native getters.', + false, + { + for: 'ember-source', + id: 'ember-object.uniq-deprecated', + since: { available: '7.9.0' }, + until: '8.0.0', + } + ); + assert( - 'You attempted to use @uniq/@union as a decorator directly, but it requires atleast one dependent key parameter', + 'You attempted to use @uniq/@union as a decorator directly, but it requires at least one dependent key parameter', !isElementDescriptor(Array.prototype.slice.call(arguments)) ); @@ -704,7 +789,7 @@ export function uniq( return multiArrayMacro( args, function (this: unknown, dependentKeys) { - let uniq = emberA(); + let uniq = disableArrayDeprecations(() => emberA()); let seen = new Set(); dependentKeys.forEach((dependentKey) => { @@ -763,6 +848,13 @@ export function uniq( @public */ export function uniqBy(dependentKey: string, propertyKey: string) { + deprecate('The @uniqBy decorator is deprecated. Use TrackedArray with native getters.', false, { + for: 'ember-source', + id: 'ember-object.uniqBy-deprecated', + since: { available: '7.9.0' }, + until: '8.0.0', + }); + assert( 'You attempted to use @uniqBy as a decorator directly, but it requires `dependentKey` and `propertyKey` parameters', !isElementDescriptor(Array.prototype.slice.call(arguments)) @@ -775,7 +867,9 @@ export function uniqBy(dependentKey: string, propertyKey: string) { return computed(`${dependentKey}.[]`, function () { let list = get(this, dependentKey); - return isNativeOrEmberArray(list) ? uniqByArray(list, propertyKey) : emberA(); + return disableArrayDeprecations(() => + isNativeOrEmberArray(list) ? uniqByArray(list, propertyKey) : emberA() + ); }).readOnly() as PropertyDecorator; } @@ -862,6 +956,17 @@ export let union = uniq; @public */ export function intersect(dependentKey: string, ...additionalDependentKeys: string[]) { + deprecate( + 'The @intersect decorator is deprecated. Use TrackedArray with native getters.', + false, + { + for: 'ember-source', + id: 'ember-object.intersect-deprecated', + since: { available: '7.9.0' }, + until: '8.0.0', + } + ); + assert( 'You attempted to use @intersect as a decorator directly, but it requires atleast one dependent key parameter', !isElementDescriptor(Array.prototype.slice.call(arguments)) @@ -951,6 +1056,13 @@ export function intersect(dependentKey: string, ...additionalDependentKeys: stri @public */ export function setDiff(setAProperty: string, setBProperty: string) { + deprecate('The @setDiff decorator is deprecated. Use TrackedArray with native getters.', false, { + for: 'ember-source', + id: 'ember-object.setDiff-deprecated', + since: { available: '7.9.0' }, + until: '8.0.0', + }); + assert( 'You attempted to use @setDiff as a decorator directly, but it requires atleast one dependent key parameter', !isElementDescriptor(Array.prototype.slice.call(arguments)) @@ -1002,6 +1114,7 @@ export function setDiff(setAProperty: string, setBProperty: string) { @method collect @for @ember/object/computed + @deprecated Use TrackedArray with native getters @static @param {String} dependentKey* @return {ComputedProperty} computed property which maps values of all passed @@ -1009,6 +1122,13 @@ export function setDiff(setAProperty: string, setBProperty: string) { @public */ export function collect(dependentKey: string, ...additionalDependentKeys: string[]) { + deprecate('The @collect decorator is deprecated. Use TrackedArray with native getters.', false, { + for: 'ember-source', + id: 'ember-object.collect-deprecated', + since: { available: '7.9.0' }, + until: '8.0.0', + }); + assert( 'You attempted to use @collect as a decorator directly, but it requires atleast one dependent key parameter', !isElementDescriptor(Array.prototype.slice.call(arguments)) @@ -1186,6 +1306,13 @@ export function sort( additionalDependentKeysOrDefinition: SortDefinition | string | string[], sortDefinition?: SortDefinition ): PropertyDecorator { + deprecate('The @sort decorator is deprecated. Use TrackedArray with native getters.', false, { + for: 'ember-source', + id: 'ember-object.sort-deprecated', + since: { available: '7.9.0' }, + until: '8.0.0', + }); + assert( 'You attempted to use @sort as a decorator directly, but it requires atleast an `itemsKey` parameter', !isElementDescriptor(Array.prototype.slice.call(arguments)) @@ -1260,11 +1387,12 @@ function propertySort(itemsKey: string, sortPropertiesKey: string): PropertyDeco let items = itemsKeyIsAtThis ? this : get(this, itemsKey); if (!isNativeOrEmberArray(items)) { - return emberA(); + return disableArrayDeprecations(() => emberA()); } if (normalizedSortProperties.length === 0) { - return emberA(items.slice()); + const arrayItems = items; + return disableArrayDeprecations(() => emberA(arrayItems.slice())); } else { return sortByNormalizedSortProperties(items, normalizedSortProperties); } @@ -1291,15 +1419,17 @@ function sortByNormalizedSortProperties( items: unknown[] | EmberArray, normalizedSortProperties: [prop: string, direction: string][] ) { - return emberA( - items.slice().sort((itemA: unknown, itemB: unknown) => { - for (let [prop, direction] of normalizedSortProperties) { - let result = compare(get(itemA, prop), get(itemB, prop)); - if (result !== 0) { - return direction === 'desc' ? -1 * result : result; + return disableArrayDeprecations(() => + emberA( + items.slice().sort((itemA: unknown, itemB: unknown) => { + for (let [prop, direction] of normalizedSortProperties) { + let result = compare(get(itemA, prop), get(itemB, prop)); + if (result !== 0) { + return direction === 'desc' ? -1 * result : result; + } } - } - return 0; - }) + return 0; + }) + ) ); } diff --git a/packages/@ember/object/mixin.ts b/packages/@ember/object/mixin.ts index 32b550c2cf9..7132529729f 100644 --- a/packages/@ember/object/mixin.ts +++ b/packages/@ember/object/mixin.ts @@ -5,7 +5,7 @@ import { INIT_FACTORY } from '@ember/-internals/container'; import type { Meta } from '@ember/-internals/meta'; import { meta as metaFor, peekMeta } from '@ember/-internals/meta'; import { guidFor, observerListenerMetaFor, ROOT, wrap } from '@ember/-internals/utils'; -import { assert } from '@ember/debug'; +import { assert, deprecate, DeprecationOptions } from '@ember/debug'; import { DEBUG } from '@glimmer/env'; import { type ComputedDecorator, @@ -14,6 +14,8 @@ import { type ComputedPropertySetter, type ComputedDescriptor, isClassicDecorator, + addListener, + removeListener, } from '@ember/-internals/metal'; import { ComputedProperty, @@ -27,7 +29,7 @@ import { defineDecorator, defineValue, } from '@ember/-internals/metal'; -import { addListener, removeListener } from '@ember/object/events'; +import { DEPRECATION, findDeprecation } from '@ember/-internals/utils/lib/mixin-deprecation'; const a_concat = Array.prototype.concat; const { isArray } = Array; @@ -543,6 +545,9 @@ export default class Mixin { /** @internal */ properties: { [key: string]: any } | undefined; + /*** @internal */ + [DEPRECATION]: { message: string; options: DeprecationOptions } | null = null; + /** @internal */ ownerConstructor: any; @@ -621,6 +626,13 @@ export default class Mixin { return this; } + if (DEBUG) { + for (let mixin of args) { + let deprecation = mixin instanceof Mixin ? findDeprecation(mixin) : null; + deprecate(deprecation?.message ?? 'Huh???', !deprecation, deprecation?.options); + } + } + if (this.properties) { let currentMixin = new Mixin(undefined, this.properties); this.properties = undefined; @@ -641,6 +653,11 @@ export default class Mixin { @internal */ apply(obj: object, _hideKeys = false) { + if (DEBUG) { + let deprecation = findDeprecation(this); + deprecate(deprecation?.message ?? 'Huh???', !deprecation, deprecation?.options); + } + // Ember.NativeArray is a normal Ember.Mixin that we mix into `Array.prototype` when prototype extensions are enabled // mutating a native object prototype like this should _not_ result in enumerable properties being added (or we have significant // issues with things like deep equality checks from test frameworks, or things like jQuery.extend(true, [], [])). @@ -662,6 +679,11 @@ export default class Mixin { @internal */ detect(obj: any): boolean { + if (DEBUG) { + let deprecation = findDeprecation(this); + deprecate(deprecation?.message ?? 'Huh???', !deprecation, deprecation?.options); + } + if (typeof obj !== 'object' || obj === null) { return false; } diff --git a/packages/@ember/object/tests/computed/computed_macros_test.js b/packages/@ember/object/tests/computed/computed_macros_test.js index 598e6ef62f3..a138820bbec 100644 --- a/packages/@ember/object/tests/computed/computed_macros_test.js +++ b/packages/@ember/object/tests/computed/computed_macros_test.js @@ -17,8 +17,12 @@ import { or, } from '@ember/object/computed'; import EmberObject, { get, set, computed, defineProperty } from '@ember/object'; -import { A as emberA } from '@ember/array'; -import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; +import { + moduleFor, + emberAWithoutDeprecation as emberA, + AbstractTestCase, + expectDeprecation, +} from 'internal-test-helpers'; moduleFor( 'CP macros', @@ -37,7 +41,9 @@ moduleFor( assert.equal(get(obj, 'bestLannisterUnspecified'), true, 'bestLannister initially empty'); assert.equal(get(obj, 'noLannistersKnown'), true, 'lannisters initially empty'); - get(obj, 'lannisters').pushObject('Tyrion'); + expectDeprecation(() => { + get(obj, 'lannisters').pushObject('Tyrion'); + }, /Usage of Ember.Array methods is deprecated/); set(obj, 'bestLannister', 'Tyrion'); assert.equal(get(obj, 'bestLannisterUnspecified'), false, 'empty respects strings'); @@ -58,7 +64,9 @@ moduleFor( assert.equal(get(obj, 'bestLannisterSpecified'), false, 'bestLannister initially empty'); assert.equal(get(obj, 'LannistersKnown'), false, 'lannisters initially empty'); - get(obj, 'lannisters').pushObject('Tyrion'); + expectDeprecation(() => { + get(obj, 'lannisters').pushObject('Tyrion'); + }, /Usage of Ember.Array methods is deprecated/); set(obj, 'bestLannister', 'Tyrion'); assert.equal(get(obj, 'bestLannisterSpecified'), true, 'empty respects strings'); diff --git a/packages/@ember/object/tests/computed/macro_decorators_test.js b/packages/@ember/object/tests/computed/macro_decorators_test.js index 18ac7329a23..aa1c5708d99 100644 --- a/packages/@ember/object/tests/computed/macro_decorators_test.js +++ b/packages/@ember/object/tests/computed/macro_decorators_test.js @@ -1,4 +1,4 @@ -import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; +import { moduleFor, AbstractTestCase, expectDeprecation } from 'internal-test-helpers'; import { alias } from '@ember/-internals/metal'; import { and, @@ -66,13 +66,15 @@ moduleFor( } ['@test collect throws an error if used without parameters']() { - expectAssertion(() => { - class Foo { - @collect foo; - } - - new Foo(); - }, /You attempted to use @collect/); + expectDeprecation(() => { + expectAssertion(() => { + class Foo { + @collect foo; + } + + new Foo(); + }, /You attempted to use @collect/); + }, /The @collect decorator is deprecated/); } ['@test deprecatingAlias throws an error if used without parameters']() { @@ -106,23 +108,27 @@ moduleFor( } ['@test filter throws an error if used without parameters']() { - expectAssertion(() => { - class Foo { - @filter foo; - } - - new Foo(); - }, /You attempted to use @filter/); + expectDeprecation(() => { + expectAssertion(() => { + class Foo { + @filter foo; + } + + new Foo(); + }, /You attempted to use @filter/); + }, /The @filter decorator is deprecated/); } ['@test filterBy throws an error if used without parameters']() { - expectAssertion(() => { - class Foo { - @filterBy foo; - } - - new Foo(); - }, /You attempted to use @filterBy/); + expectDeprecation(() => { + expectAssertion(() => { + class Foo { + @filterBy foo; + } + + new Foo(); + }, /You attempted to use @filterBy/); + }, /The @filterBy decorator is deprecated/); } ['@test gt throws an error if used without parameters']() { @@ -146,13 +152,15 @@ moduleFor( } ['@test intersect throws an error if used without parameters']() { - expectAssertion(() => { - class Foo { - @intersect foo; - } - - new Foo(); - }, /You attempted to use @intersect/); + expectDeprecation(() => { + expectAssertion(() => { + class Foo { + @intersect foo; + } + + new Foo(); + }, /You attempted to use @intersect/); + }, /The @intersect decorator is deprecated/); } ['@test lt throws an error if used without parameters']() { @@ -176,23 +184,27 @@ moduleFor( } ['@test map throws an error if used without parameters']() { - expectAssertion(() => { - class Foo { - @map foo; - } - - new Foo(); - }, /You attempted to use @map/); + expectDeprecation(() => { + expectAssertion(() => { + class Foo { + @map foo; + } + + new Foo(); + }, /You attempted to use @map/); + }, /The @map decorator is deprecated/); } ['@test mapBy throws an error if used without parameters']() { - expectAssertion(() => { - class Foo { - @mapBy foo; - } - - new Foo(); - }, /You attempted to use @mapBy/); + expectDeprecation(() => { + expectAssertion(() => { + class Foo { + @mapBy foo; + } + + new Foo(); + }, /You attempted to use @mapBy/); + }, /The @mapBy decorator is deprecated/); } ['@test match throws an error if used without parameters']() { @@ -206,23 +218,27 @@ moduleFor( } ['@test max throws an error if used without parameters']() { - expectAssertion(() => { - class Foo { - @max foo; - } - - new Foo(); - }, /You attempted to use @max/); + expectDeprecation(() => { + expectAssertion(() => { + class Foo { + @max foo; + } + + new Foo(); + }, /You attempted to use @max/); + }, /The @max decorator is deprecated/); } ['@test min throws an error if used without parameters']() { - expectAssertion(() => { - class Foo { - @min foo; - } - - new Foo(); - }, /You attempted to use @min/); + expectDeprecation(() => { + expectAssertion(() => { + class Foo { + @min foo; + } + + new Foo(); + }, /You attempted to use @min/); + }, /The @min decorator is deprecated/); } ['@test not throws an error if used without parameters']() { @@ -276,63 +292,75 @@ moduleFor( } ['@test setDiff throws an error if used without parameters']() { - expectAssertion(() => { - class Foo { - @setDiff foo; - } - - new Foo(); - }, /You attempted to use @setDiff/); + expectDeprecation(() => { + expectAssertion(() => { + class Foo { + @setDiff foo; + } + + new Foo(); + }, /You attempted to use @setDiff/); + }, /The @setDiff decorator is deprecated/); } ['@test sort throws an error if used without parameters']() { - expectAssertion(() => { - class Foo { - @sort foo; - } - - new Foo(); - }, /You attempted to use @sort/); + expectDeprecation(() => { + expectAssertion(() => { + class Foo { + @sort foo; + } + + new Foo(); + }, /You attempted to use @sort/); + }, /The @sort decorator is deprecated/); } ['@test sum throws an error if used without parameters']() { - expectAssertion(() => { - class Foo { - @sum foo; - } - - new Foo(); - }, /You attempted to use @sum/); + expectDeprecation(() => { + expectAssertion(() => { + class Foo { + @sum foo; + } + + new Foo(); + }, /You attempted to use @sum/); + }, /The @sum decorator is deprecated/); } ['@test union throws an error if used without parameters']() { - expectAssertion(() => { - class Foo { - @union foo; - } - - new Foo(); - }, /You attempted to use @uniq\/@union/); + expectDeprecation(() => { + expectAssertion(() => { + class Foo { + @union foo; + } + + new Foo(); + }, /You attempted to use @uniq\/@union/); + }, /The @uniq\/@union decorator is deprecated/); } ['@test uniq throws an error if used without parameters']() { - expectAssertion(() => { - class Foo { - @uniq foo; - } - - new Foo(); - }, /You attempted to use @uniq\/@union/); + expectDeprecation(() => { + expectAssertion(() => { + class Foo { + @uniq foo; + } + + new Foo(); + }, /You attempted to use @uniq/); + }, /The @uniq\/@union decorator is deprecated/); } ['@test uniqBy throws an error if used without parameters']() { - expectAssertion(() => { - class Foo { - @uniqBy foo; - } - - new Foo(); - }, /You attempted to use @uniqBy/); + expectDeprecation(() => { + expectAssertion(() => { + class Foo { + @uniqBy foo; + } + + new Foo(); + }, /You attempted to use @uniqBy/); + }, /The @uniqBy decorator is deprecated/); } } ); diff --git a/packages/@ember/object/tests/computed/reduce_computed_macros_test.js b/packages/@ember/object/tests/computed/reduce_computed_macros_test.js index 0a64fa17130..a266dfbad1b 100644 --- a/packages/@ember/object/tests/computed/reduce_computed_macros_test.js +++ b/packages/@ember/object/tests/computed/reduce_computed_macros_test.js @@ -9,7 +9,7 @@ import EmberObject, { observer, } from '@ember/object'; import ObjectProxy from '@ember/object/proxy'; -import { isArray, A as emberA, removeAt } from '@ember/array'; +import { isArray, removeAt } from '@ember/array'; import { sum, min, @@ -26,26 +26,34 @@ import { intersect, collect, } from '@ember/object/computed'; -import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { + moduleFor, + AbstractTestCase, + runLoopSettled, + expectDeprecation, + emberAWithoutDeprecation as emberA, +} from 'internal-test-helpers'; let obj; moduleFor( 'map', class extends AbstractTestCase { beforeEach() { - obj = class extends EmberObject { - @map('array.@each.v', (item) => item.v) - mapped; - - @map('arrayObjects.@each.v', (item) => ({ - name: item.v.name, - })) - mappedObjects; - }.create({ - arrayObjects: emberA([{ v: { name: 'Robert' } }, { v: { name: 'Leanna' } }]), - - array: emberA([{ v: 1 }, { v: 3 }, { v: 2 }, { v: 1 }]), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @map('array.@each.v', (item) => item.v) + mapped; + + @map('arrayObjects.@each.v', (item) => ({ + name: item.v.name, + })) + mappedObjects; + }.create({ + arrayObjects: emberA([{ v: { name: 'Robert' } }, { v: { name: 'Leanna' } }]), + + array: emberA([{ v: 1 }, { v: 3 }, { v: 2 }, { v: 1 }]), + }); + }, /The @map decorator is deprecated/); } afterEach() { @@ -61,7 +69,9 @@ moduleFor( ['@test it maps simple properties'](assert) { assert.deepEqual(obj.get('mapped'), [1, 3, 2, 1]); - obj.get('array').pushObject({ v: 5 }); + expectDeprecation(() => { + obj.get('array').pushObject({ v: 5 }); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual(obj.get('mapped'), [1, 3, 2, 1, 5]); @@ -73,18 +83,24 @@ moduleFor( ['@test it maps simple unshifted properties'](assert) { let array = emberA(); - obj = class extends EmberObject { - @map('array', (item) => item.toUpperCase()) - mapped; - }.create({ - array, - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @map('array', (item) => item.toUpperCase()) + mapped; + }.create({ + array, + }); + }, /The @map decorator is deprecated/); - array.unshiftObject('c'); - array.unshiftObject('b'); - array.unshiftObject('a'); + expectDeprecation(() => { + array.unshiftObject('c'); + array.unshiftObject('b'); + array.unshiftObject('a'); + }, /Usage of Ember.Array methods is deprecated/); - array.popObject(); + expectDeprecation(() => { + array.popObject(); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( obj.get('mapped'), @@ -94,19 +110,21 @@ moduleFor( } ['@test it has the correct `this`'](assert) { - obj = class extends EmberObject { - @map('array', function (item) { - assert.equal(this, obj, 'should have correct context'); - return this.upperCase(item); - }) - mapped; - - upperCase(string) { - return string.toUpperCase(); - } - }.create({ - array: ['a', 'b', 'c'], - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @map('array', function (item) { + assert.equal(this, obj, 'should have correct context'); + return this.upperCase(item); + }) + mapped; + + upperCase(string) { + return string.toUpperCase(); + } + }.create({ + array: ['a', 'b', 'c'], + }); + }, /The @map decorator is deprecated/); assert.deepEqual( obj.get('mapped'), @@ -118,12 +136,14 @@ moduleFor( ['@test it passes the index to the callback'](assert) { let array = ['a', 'b', 'c']; - obj = class extends EmberObject { - @map('array', (item, index) => index) - mapped; - }.create({ - array, - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @map('array', (item, index) => index) + mapped; + }.create({ + array, + }); + }, /The @map decorator is deprecated/); assert.deepEqual(obj.get('mapped'), [0, 1, 2], 'index is passed to callback correctly'); } @@ -131,9 +151,11 @@ moduleFor( ['@test it maps objects'](assert) { assert.deepEqual(obj.get('mappedObjects'), [{ name: 'Robert' }, { name: 'Leanna' }]); - obj.get('arrayObjects').pushObject({ - v: { name: 'Eddard' }, - }); + expectDeprecation(() => { + obj.get('arrayObjects').pushObject({ + v: { name: 'Eddard' }, + }); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual(obj.get('mappedObjects'), [ { name: 'Robert' }, @@ -154,20 +176,28 @@ moduleFor( let array = emberA(); let cObj = { v: 'c' }; - obj = class extends EmberObject { - @map('array.@each.v', (item) => get(item, 'v').toUpperCase()) - mapped; - }.create({ - array, - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @map('array.@each.v', (item) => get(item, 'v').toUpperCase()) + mapped; + }.create({ + array, + }); + }, /The @map decorator is deprecated/); - array.unshiftObject(cObj); - array.unshiftObject({ v: 'b' }); - array.unshiftObject({ v: 'a' }); + expectDeprecation(() => { + array.unshiftObject(cObj); + array.unshiftObject({ v: 'b' }); + array.unshiftObject({ v: 'a' }); + }, /Usage of Ember.Array methods is deprecated/); set(cObj, 'v', 'd'); - assert.deepEqual(array.mapBy('v'), ['a', 'b', 'd'], 'precond - unmapped array is correct'); + assert.deepEqual( + array.map((i) => i.v), + ['a', 'b', 'd'], + 'precond - unmapped array is correct' + ); assert.deepEqual( obj.get('mapped'), ['A', 'B', 'D'], @@ -176,15 +206,17 @@ moduleFor( } ['@test it updates if additional dependent keys are modified'](assert) { - obj = class extends EmberObject { - @map('array', ['key'], function (item) { - return item[this.key]; - }) - mapped; - }.create({ - key: 'name', - array: emberA([{ name: 'Cercei', house: 'Lannister' }]), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @map('array', ['key'], function (item) { + return item[this.key]; + }) + mapped; + }.create({ + key: 'name', + array: emberA([{ name: 'Cercei', house: 'Lannister' }]), + }); + }, /The @map decorator is deprecated/); assert.deepEqual( obj.get('mapped'), @@ -201,21 +233,23 @@ moduleFor( } ['@test it throws on bad inputs']() { - expectAssertion(() => { - map('items.@each.{prop}', 'foo'); - }, /The final parameter provided to map must be a callback function/); + expectDeprecation(() => { + expectAssertion(() => { + map('items.@each.{prop}', 'foo'); + }, /The final parameter provided to map must be a callback function/); - expectAssertion(() => { - map('items.@each.{prop}', 'foo', function () {}); - }, /The second parameter provided to map must either be the callback or an array of additional dependent keys/); + expectAssertion(() => { + map('items.@each.{prop}', 'foo', function () {}); + }, /The second parameter provided to map must either be the callback or an array of additional dependent keys/); - expectAssertion(() => { - map('items.@each.{prop}', function () {}, ['foo']); - }, /The final parameter provided to map must be a callback function/); + expectAssertion(() => { + map('items.@each.{prop}', function () {}, ['foo']); + }, /The final parameter provided to map must be a callback function/); - expectAssertion(() => { - map('items.@each.{prop}', ['foo']); - }, /The final parameter provided to map must be a callback function/); + expectAssertion(() => { + map('items.@each.{prop}', ['foo']); + }, /The final parameter provided to map must be a callback function/); + }, /The @map decorator is deprecated/); } } ); @@ -224,12 +258,14 @@ moduleFor( 'mapBy', class extends AbstractTestCase { beforeEach() { - obj = class extends EmberObject { - @mapBy('array', 'v') - mapped; - }.create({ - array: emberA([{ v: 1 }, { v: 3 }, { v: 2 }, { v: 1 }]), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @mapBy('array', 'v') + mapped; + }.create({ + array: emberA([{ v: 1 }, { v: 3 }, { v: 2 }, { v: 1 }]), + }); + }, /The @mapBy decorator is deprecated/); } afterEach() { @@ -245,7 +281,9 @@ moduleFor( ['@test it maps properties'](assert) { assert.deepEqual(obj.get('mapped'), [1, 3, 2, 1]); - obj.get('array').pushObject({ v: 5 }); + expectDeprecation(() => { + obj.get('array').pushObject({ v: 5 }); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual(obj.get('mapped'), [1, 3, 2, 1, 5]); @@ -261,7 +299,10 @@ moduleFor( addObserver(obj, 'mapped.@each', () => calls++); - obj.get('array').pushObject({ v: 5 }); + expectDeprecation(() => { + obj.get('array').pushObject({ v: 5 }); + }, /Usage of Ember.Array methods is deprecated/); + await runLoopSettled(); assert.equal(calls, 1, 'mapBy is observable'); @@ -273,12 +314,14 @@ moduleFor( 'filter', class extends AbstractTestCase { beforeEach() { - obj = class extends EmberObject { - @filter('array', (item) => item % 2 === 0) - filtered; - }.create({ - array: emberA([1, 2, 3, 4, 5, 6, 7, 8]), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @filter('array', (item) => item % 2 === 0) + filtered; + }.create({ + array: emberA([1, 2, 3, 4, 5, 6, 7, 8]), + }); + }, /The @filter decorator is deprecated/); } afterEach() { @@ -300,41 +343,47 @@ moduleFor( } ['@test it passes the index to the callback'](assert) { - obj = class extends EmberObject { - @filter('array', (item, index) => index === 1) - filtered; - }.create({ - array: ['a', 'b', 'c'], - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @filter('array', (item, index) => index === 1) + filtered; + }.create({ + array: ['a', 'b', 'c'], + }); + }, /The @filter decorator is deprecated/); assert.deepEqual(get(obj, 'filtered'), ['b'], 'index is passed to callback correctly'); } ['@test it has the correct `this`'](assert) { - obj = class extends EmberObject { - @filter('array', function (item, index) { - assert.equal(this, obj); - return this.isOne(index); - }) - filtered; - - isOne(value) { - return value === 1; - } - }.create({ - array: ['a', 'b', 'c'], - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @filter('array', function (item, index) { + assert.equal(this, obj); + return this.isOne(index); + }) + filtered; + + isOne(value) { + return value === 1; + } + }.create({ + array: ['a', 'b', 'c'], + }); + }, /The @filter decorator is deprecated/); assert.deepEqual(get(obj, 'filtered'), ['b'], 'index is passed to callback correctly'); } ['@test it passes the array to the callback'](assert) { - obj = class extends EmberObject { - @filter('array', (item, index, array) => index === get(array, 'length') - 2) - filtered; - }.create({ - array: emberA(['a', 'b', 'c']), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @filter('array', (item, index, array) => index === get(array, 'length') - 2) + filtered; + }.create({ + array: emberA(['a', 'b', 'c']), + }); + }, /The @filter decorator is deprecated/); assert.deepEqual(obj.get('filtered'), ['b'], 'array is passed to callback correctly'); } @@ -345,7 +394,10 @@ moduleFor( let filtered = obj.get('filtered'); assert.ok(filtered === obj.get('filtered')); - array.addObject(11); + expectDeprecation(() => { + array.addObject(11); + }, /Usage of Ember.Array methods is deprecated/); + let newFiltered = obj.get('filtered'); assert.ok(filtered !== newFiltered); @@ -362,22 +414,30 @@ moduleFor( 'precond - filtered array is initially correct' ); - array.addObject(11); + expectDeprecation(() => { + array.addObject(11); + }, /Usage of Ember.Array methods is deprecated/); + assert.deepEqual( obj.get('filtered'), [2, 4, 6, 8], 'objects not passing the filter are not added' ); - array.addObject(12); + expectDeprecation(() => { + array.addObject(12); + }, /Usage of Ember.Array methods is deprecated/); + assert.deepEqual( obj.get('filtered'), [2, 4, 6, 8, 12], 'objects passing the filter are added' ); - array.removeObject(3); - array.removeObject(4); + expectDeprecation(() => { + array.removeObject(3); + array.removeObject(4); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( obj.get('filtered'), @@ -395,15 +455,16 @@ moduleFor( 'precond - filtered array is initially correct' ); - // clear 1-8 but in a random order - array.removeObject(3); - array.removeObject(1); - array.removeObject(2); - array.removeObject(4); - array.removeObject(8); - array.removeObject(6); - array.removeObject(5); - array.removeObject(7); + expectDeprecation(() => { + array.removeObject(3); + array.removeObject(1); + array.removeObject(2); + array.removeObject(4); + array.removeObject(8); + array.removeObject(6); + array.removeObject(5); + array.removeObject(7); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual(obj.get('filtered'), [], 'filtered array cleared correctly'); } @@ -415,7 +476,9 @@ moduleFor( 'precond - filtered array is initially correct' ); - obj.get('array').clear(); + expectDeprecation(() => { + obj.get('array').clear(); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual(obj.get('filtered'), [], 'filtered array cleared correctly'); } @@ -439,12 +502,14 @@ moduleFor( ['@test it updates properly on @each with {} dependencies'](assert) { let item = EmberObject.create({ prop: true }); - obj = class extends EmberObject { - @filter('items.@each.{prop}', (item) => item.get('prop') === true) - filtered; - }.create({ - items: emberA([item]), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @filter('items.@each.{prop}', (item) => item.get('prop') === true) + filtered; + }.create({ + items: emberA([item]), + }); + }, /The @filter decorator is deprecated/); assert.deepEqual(obj.get('filtered'), [item]); @@ -454,15 +519,17 @@ moduleFor( } ['@test it updates if additional dependent keys are modified'](assert) { - obj = class extends EmberObject { - @filter('array', ['modulo'], function (item) { - return item % this.modulo === 0; - }) - filtered; - }.create({ - modulo: 2, - array: emberA([1, 2, 3, 4, 5, 6, 7, 8]), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @filter('array', ['modulo'], function (item) { + return item % this.modulo === 0; + }) + filtered; + }.create({ + modulo: 2, + array: emberA([1, 2, 3, 4, 5, 6, 7, 8]), + }); + }, /The @filter decorator is deprecated/); assert.deepEqual( obj.get('filtered'), @@ -479,21 +546,23 @@ moduleFor( } ['@test it throws on bad inputs']() { - expectAssertion(() => { - filter('items.@each.{prop}', 'foo'); - }, /The final parameter provided to filter must be a callback function/); + expectDeprecation(() => { + expectAssertion(() => { + filter('items.@each.{prop}', 'foo'); + }, /The final parameter provided to filter must be a callback function/); - expectAssertion(() => { - filter('items.@each.{prop}', 'foo', function () {}); - }, /The second parameter provided to filter must either be the callback or an array of additional dependent keys/); + expectAssertion(() => { + filter('items.@each.{prop}', 'foo', function () {}); + }, /The second parameter provided to filter must either be the callback or an array of additional dependent keys/); - expectAssertion(() => { - filter('items.@each.{prop}', function () {}, ['foo']); - }, /The final parameter provided to filter must be a callback function/); + expectAssertion(() => { + filter('items.@each.{prop}', function () {}, ['foo']); + }, /The final parameter provided to filter must be a callback function/); - expectAssertion(() => { - filter('items.@each.{prop}', ['foo']); - }, /The final parameter provided to filter must be a callback function/); + expectAssertion(() => { + filter('items.@each.{prop}', ['foo']); + }, /The final parameter provided to filter must be a callback function/); + }, /The @filter decorator is deprecated/); } } ); @@ -502,21 +571,23 @@ moduleFor( 'filterBy', class extends AbstractTestCase { beforeEach() { - obj = class extends EmberObject { - @filterBy('array', 'a', 1) - a1s; - @filterBy('array', 'a') - as; - @filterBy('array', 'b') - bs; - }.create({ - array: emberA([ - { name: 'one', a: 1, b: false }, - { name: 'two', a: 2, b: false }, - { name: 'three', a: 1, b: true }, - { name: 'four', b: true }, - ]), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @filterBy('array', 'a', 1) + a1s; + @filterBy('array', 'a') + as; + @filterBy('array', 'b') + bs; + }.create({ + array: emberA([ + { name: 'one', a: 1, b: false }, + { name: 'two', a: 2, b: false }, + { name: 'three', a: 1, b: true }, + { name: 'four', b: true }, + ]), + }); + }, /The @filterBy decorator is deprecated/); } afterEach() { @@ -531,11 +602,15 @@ moduleFor( ['@test properties can be filtered by truthiness'](assert) { assert.deepEqual( - obj.get('as').mapBy('name'), + obj.get('as').map((i) => i.name), ['one', 'two', 'three'], 'properties can be filtered by existence' ); - assert.deepEqual(obj.get('bs').mapBy('name'), ['three', 'four'], 'booleans can be filtered'); + assert.deepEqual( + obj.get('bs').map((i) => i.name), + ['three', 'four'], + 'booleans can be filtered' + ); set(obj.get('array')[0], 'a', undefined); set(obj.get('array')[3], 'a', true); @@ -544,38 +619,42 @@ moduleFor( set(obj.get('array')[3], 'b', false); assert.deepEqual( - obj.get('as').mapBy('name'), + obj.get('as').map((i) => i.name), ['two', 'three', 'four'], 'arrays computed by filter property respond to property changes' ); assert.deepEqual( - obj.get('bs').mapBy('name'), + obj.get('bs').map((i) => i.name), ['one', 'three'], 'arrays computed by filtered property respond to property changes' ); - obj.get('array').pushObject({ name: 'five', a: 6, b: true }); + expectDeprecation(() => { + obj.get('array').pushObject({ name: 'five', a: 6, b: true }); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( - obj.get('as').mapBy('name'), + obj.get('as').map((i) => i.name), ['two', 'three', 'four', 'five'], 'arrays computed by filter property respond to added objects' ); assert.deepEqual( - obj.get('bs').mapBy('name'), + obj.get('bs').map((i) => i.name), ['one', 'three', 'five'], 'arrays computed by filtered property respond to added objects' ); - obj.get('array').popObject(); + expectDeprecation(() => { + obj.get('array').popObject(); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( - obj.get('as').mapBy('name'), + obj.get('as').map((i) => i.name), ['two', 'three', 'four'], 'arrays computed by filter property respond to removed objects' ); assert.deepEqual( - obj.get('bs').mapBy('name'), + obj.get('bs').map((i) => i.name), ['one', 'three'], 'arrays computed by filtered property respond to removed objects' ); @@ -583,12 +662,12 @@ moduleFor( obj.set('array', [{ name: 'six', a: 12, b: true }]); assert.deepEqual( - obj.get('as').mapBy('name'), + obj.get('as').map((i) => i.name), ['six'], 'arrays computed by filter property respond to array changes' ); assert.deepEqual( - obj.get('bs').mapBy('name'), + obj.get('bs').map((i) => i.name), ['six'], 'arrays computed by filtered property respond to array changes' ); @@ -596,23 +675,27 @@ moduleFor( ['@test properties can be filtered by values'](assert) { assert.deepEqual( - obj.get('a1s').mapBy('name'), + obj.get('a1s').map((i) => i.name), ['one', 'three'], 'properties can be filtered by matching value' ); - obj.get('array').pushObject({ name: 'five', a: 1 }); + expectDeprecation(() => { + obj.get('array').pushObject({ name: 'five', a: 1 }); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( - obj.get('a1s').mapBy('name'), + obj.get('a1s').map((i) => i.name), ['one', 'three', 'five'], 'arrays computed by matching value respond to added objects' ); - obj.get('array').popObject(); + expectDeprecation(() => { + obj.get('array').popObject(); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( - obj.get('a1s').mapBy('name'), + obj.get('a1s').map((i) => i.name), ['one', 'three'], 'arrays computed by matching value respond to removed objects' ); @@ -621,24 +704,26 @@ moduleFor( set(obj.get('array')[2], 'a', 2); assert.deepEqual( - obj.get('a1s').mapBy('name'), + obj.get('a1s').map((i) => i.name), ['one', 'two'], 'arrays computed by matching value respond to modified properties' ); } ['@test properties values can be replaced'](assert) { - obj = class extends EmberObject { - @filterBy('array', 'a', 1) - a1s; - @filterBy('a1s', 'b') - a1bs; - }.create({ - array: [], - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @filterBy('array', 'a', 1) + a1s; + @filterBy('a1s', 'b') + a1bs; + }.create({ + array: [], + }); + }, /The @filterBy decorator is deprecated/); assert.deepEqual( - obj.get('a1bs').mapBy('name'), + obj.get('a1bs').map((i) => i.name), [], 'properties can be filtered by matching value' ); @@ -646,7 +731,7 @@ moduleFor( set(obj, 'array', [{ name: 'item1', a: 1, b: true }]); assert.deepEqual( - obj.get('a1bs').mapBy('name'), + obj.get('a1bs').map((i) => i.name), ['item1'], 'properties can be filtered by matching value' ); @@ -664,14 +749,16 @@ moduleFor( `CP macro \`${name}\``, class extends AbstractTestCase { beforeEach() { - obj = class extends EmberObject { - @macro('array', 'array2', 'array3') - union; - }.create({ - array: emberA([1, 2, 3, 4, 5, 6]), - array2: emberA([4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9]), - array3: emberA([1, 8, 10]), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @macro('array', 'array2', 'array3') + union; + }.create({ + array: emberA([1, 2, 3, 4, 5, 6]), + array2: emberA([4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9]), + array3: emberA([1, 8, 10]), + }); + }, /The @uniq\/@union decorator is deprecated/); } afterEach() { @@ -694,7 +781,9 @@ moduleFor( name + ' does not include duplicates' ); - array.pushObject(8); + expectDeprecation(() => { + array.pushObject(8); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( obj.get('union').sort((x, y) => x - y), @@ -702,7 +791,9 @@ moduleFor( name + ' does not add existing items' ); - array.pushObject(11); + expectDeprecation(() => { + array.pushObject(11); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( obj.get('union').sort((x, y) => x - y), @@ -718,7 +809,9 @@ moduleFor( name + ' does not remove items that are still in the dependent array' ); - array2.removeObject(7); + expectDeprecation(() => { + array2.removeObject(7); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( obj.get('union').sort((x, y) => x - y), @@ -736,7 +829,9 @@ moduleFor( name + ' is initially correct' ); - array.removeObject(6); + expectDeprecation(() => { + array.removeObject(6); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( obj.get('union').sort((x, y) => x - y), @@ -744,7 +839,9 @@ moduleFor( 'objects are not removed if they exist in other dependent arrays' ); - array.clear(); + expectDeprecation(() => { + array.clear(); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( obj.get('union').sort((x, y) => x - y), @@ -760,17 +857,19 @@ moduleFor( 'CP Macro `uniqBy`', class extends AbstractTestCase { beforeEach() { - obj = class extends EmberObject { - list = null; - @uniqBy('list', 'id') - uniqueById; - }.create({ - list: emberA([ - { id: 1, value: 'one' }, - { id: 2, value: 'two' }, - { id: 1, value: 'one' }, - ]), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + list = null; + @uniqBy('list', 'id') + uniqueById; + }.create({ + list: emberA([ + { id: 1, value: 'one' }, + { id: 2, value: 'two' }, + { id: 1, value: 'one' }, + ]), + }); + }, /The @uniqBy decorator is deprecated/); } afterEach() { @@ -790,11 +889,14 @@ moduleFor( } ['@test it does not share state among instances'](assert) { - let MyObject = class extends EmberObject { - list = []; - @uniqBy('list', 'name') - uniqueByName; - }; + let MyObject; + expectDeprecation(() => { + MyObject = class extends EmberObject { + list = []; + @uniqBy('list', 'name') + uniqueByName; + }; + }, /The @uniqBy decorator is deprecated/); let a = MyObject.create({ list: [{ name: 'bob' }, { name: 'mitch' }, { name: 'mitch' }], }); @@ -808,7 +910,9 @@ moduleFor( } ['@test it handles changes to the dependent array'](assert) { - obj.get('list').pushObject({ id: 3, value: 'three' }); + expectDeprecation(() => { + obj.get('list').pushObject({ id: 3, value: 'three' }); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( obj.get('uniqueById'), @@ -820,7 +924,9 @@ moduleFor( 'The list includes three' ); - obj.get('list').pushObject({ id: 3, value: 'three' }); + expectDeprecation(() => { + obj.get('list').pushObject({ id: 3, value: 'three' }); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( obj.get('uniqueById'), @@ -834,11 +940,15 @@ moduleFor( } ['@test it returns an empty array when computed on a non-array'](assert) { - let MyObject = class extends EmberObject { - list = null; - @uniqBy('list', 'name') - uniq; - }; + let MyObject; + expectDeprecation(() => { + MyObject = class extends EmberObject { + list = null; + @uniqBy('list', 'name') + uniq; + }; + }, /The @uniqBy decorator is deprecated/); + let a = MyObject.create({ list: 'not an array' }); assert.deepEqual(a.get('uniq'), []); @@ -850,14 +960,16 @@ moduleFor( 'CP Macro `intersect`', class extends AbstractTestCase { beforeEach() { - obj = class extends EmberObject { - @intersect('array', 'array2', 'array3') - intersection; - }.create({ - array: emberA([1, 2, 3, 4, 5, 6]), - array2: emberA([3, 3, 3, 4, 5]), - array3: emberA([3, 5, 6, 7, 8]), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @intersect('array', 'array2', 'array3') + intersection; + }.create({ + array: emberA([1, 2, 3, 4, 5, 6]), + array2: emberA([3, 3, 3, 4, 5]), + array3: emberA([3, 5, 6, 7, 8]), + }); + }, /The @intersect decorator is deprecated/); } afterEach() { @@ -880,7 +992,9 @@ moduleFor( 'intersection is initially correct' ); - array2.shiftObject(); + expectDeprecation(() => { + array2.shiftObject(); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( obj.get('intersection').sort((x, y) => x - y), @@ -888,7 +1002,9 @@ moduleFor( 'objects are not removed when they are still in all dependent arrays' ); - array2.shiftObject(); + expectDeprecation(() => { + array2.shiftObject(); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( obj.get('intersection').sort((x, y) => x - y), @@ -896,7 +1012,9 @@ moduleFor( 'objects are not removed when they are still in all dependent arrays' ); - array2.shiftObject(); + expectDeprecation(() => { + array2.shiftObject(); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( obj.get('intersection'), @@ -904,7 +1022,9 @@ moduleFor( 'objects are removed once they are gone from all dependent arrays' ); - array2.pushObject(1); + expectDeprecation(() => { + array2.pushObject(1); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( obj.get('intersection'), @@ -912,7 +1032,9 @@ moduleFor( 'objects are not added as long as they are missing from any dependent array' ); - array3.pushObject(1); + expectDeprecation(() => { + array3.pushObject(1); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( obj.get('intersection').sort((x, y) => x - y), @@ -927,13 +1049,15 @@ moduleFor( 'setDiff', class extends AbstractTestCase { beforeEach() { - obj = class extends EmberObject { - @setDiff('array', 'array2') - diff; - }.create({ - array: emberA([1, 2, 3, 4, 5, 6, 7]), - array2: emberA([3, 4, 5, 10]), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @setDiff('array', 'array2') + diff; + }.create({ + array: emberA([1, 2, 3, 4, 5, 6, 7]), + array2: emberA([3, 4, 5, 10]), + }); + }, /The @setDiff decorator is deprecated/); } afterEach() { @@ -949,10 +1073,13 @@ moduleFor( ['@test it asserts if given fewer or more than two dependent properties']() { expectAssertion( function () { - let TestClass = class extends EmberObject { - @setDiff('array') - diff; - }; + let TestClass; + expectDeprecation(() => { + TestClass = class extends EmberObject { + @setDiff('array') + diff; + }; + }, /The @setDiff decorator is deprecated/); TestClass.create({ array: emberA([1, 2, 3, 4, 5, 6, 7]), array2: emberA([3, 4, 5]), @@ -964,10 +1091,13 @@ moduleFor( expectAssertion( function () { - let TestClass = class extends EmberObject { - @setDiff('array', 'array2', 'array3') - diff; - }; + let TestClass; + expectDeprecation(() => { + TestClass = class extends EmberObject { + @setDiff('array', 'array2', 'array3') + diff; + }; + }, /The @setDiff decorator is deprecated/); TestClass.create({ array: emberA([1, 2, 3, 4, 5, 6, 7]), array2: emberA([3, 4, 5]), @@ -989,7 +1119,9 @@ moduleFor( 'set-diff is initially correct' ); - array2.popObject(); + expectDeprecation(() => { + array2.popObject(); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( obj.get('diff').sort((x, y) => x - y), @@ -997,7 +1129,9 @@ moduleFor( 'removing objects from the remove set has no effect if the object is not in the keep set' ); - array2.shiftObject(); + expectDeprecation(() => { + array2.shiftObject(); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( obj.get('diff').sort((x, y) => x - y), @@ -1005,7 +1139,9 @@ moduleFor( "removing objects from the remove set adds them if they're in the keep set" ); - array1.removeObject(3); + expectDeprecation(() => { + array1.removeObject(3); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( obj.get('diff').sort((x, y) => x - y), @@ -1013,7 +1149,9 @@ moduleFor( 'removing objects from the keep array removes them from the computed array' ); - array1.pushObject(5); + expectDeprecation(() => { + array1.pushObject(5); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( obj.get('diff').sort((x, y) => x - y), @@ -1021,7 +1159,9 @@ moduleFor( 'objects added to the keep array that are in the remove array are not added to the computed array' ); - array1.pushObject(22); + expectDeprecation(() => { + array1.pushObject(22); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( obj.get('diff').sort((x, y) => x - y), @@ -1051,7 +1191,7 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { ['@test arrays are initially sorted'](assert) { assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'array is initially sorted' ); @@ -1059,7 +1199,7 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { ['@test default sort order is correct'](assert) { assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'array is initially sorted' ); @@ -1067,7 +1207,7 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { ['@test changing the dependent array updates the sorted array'](assert) { assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted' ); @@ -1080,7 +1220,7 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { ]); assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Stannis', 'Ramsey', 'Roose', 'Theon'], 'changing dependent array updates sorted array' ); @@ -1090,18 +1230,20 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { let items = this.obj.items; assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted' ); - items.pushObject({ - fname: 'Tyrion', - lname: 'Lannister', - }); + expectDeprecation(() => { + items.pushObject({ + fname: 'Tyrion', + lname: 'Lannister', + }); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Cersei', 'Jaime', 'Tyrion', 'Bran', 'Robb'], 'Adding to the dependent array updates the sorted array' ); @@ -1109,15 +1251,17 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { ['@test removing from the dependent array updates the sorted array'](assert) { assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted' ); - this.obj.items.popObject(); + expectDeprecation(() => { + this.obj.items.popObject(); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Cersei', 'Jaime', 'Robb'], 'Removing from the dependent array updates the sorted array' ); @@ -1142,11 +1286,13 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { let items = this.obj.items; - items.replace(0, 1, [jaime]); - items.replace(1, 1, [jaimeInDisguise]); + expectDeprecation(() => { + items.replace(0, 1, [jaime]); + items.replace(1, 1, [jaimeInDisguise]); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted' ); @@ -1154,7 +1300,7 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { set(jaimeInDisguise, 'fname', 'Jaime'); assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Jaime', 'Jaime', 'Bran', 'Robb'], 'sorted array is updated' ); @@ -1162,7 +1308,7 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { set(jaimeInDisguise, 'fname', 'Cersei'); assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'sorted array is updated' ); @@ -1184,33 +1330,30 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { let items = this.obj.items; - items.pushObject(tyrion); + expectDeprecation(() => { + items.pushObject(tyrion); + }, /Usage of Ember.Array methods is deprecated/); - assert.deepEqual(this.obj.sortedItems.mapBy('fname'), [ - 'Cersei', - 'Jaime', - 'Tyrion', - 'Bran', - 'Robb', - ]); + assert.deepEqual( + this.obj.sortedItems.map((i) => i.fname), + ['Cersei', 'Jaime', 'Tyrion', 'Bran', 'Robb'] + ); - items.pushObject(tyrionInDisguise); + expectDeprecation(() => { + items.pushObject(tyrionInDisguise); + }, /Usage of Ember.Array methods is deprecated/); - assert.deepEqual(this.obj.sortedItems.mapBy('fname'), [ - 'Yollo', - 'Cersei', - 'Jaime', - 'Tyrion', - 'Bran', - 'Robb', - ]); + assert.deepEqual( + this.obj.sortedItems.map((i) => i.fname), + ['Yollo', 'Cersei', 'Jaime', 'Tyrion', 'Bran', 'Robb'] + ); } ['@test updating sort properties detaches observers for old sort properties'](assert) { let objectToRemove = this.obj.items[3]; assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted' ); @@ -1218,15 +1361,17 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { set(this.obj, 'itemSorting', emberA(['fname:desc'])); assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Robb', 'Jaime', 'Cersei', 'Bran'], 'after updating sort properties array is updated' ); - this.obj.items.removeObject(objectToRemove); + expectDeprecation(() => { + this.obj.items.removeObject(objectToRemove); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Robb', 'Jaime', 'Cersei'], 'after removing item array is updated' ); @@ -1234,7 +1379,7 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { set(objectToRemove, 'lname', 'Updated-Stark'); assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Robb', 'Jaime', 'Cersei'], 'after changing removed item array is not updated' ); @@ -1251,7 +1396,7 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { ['@test updating sort properties updates the sorted array'](assert) { assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted' ); @@ -1259,7 +1404,7 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { set(this.obj, 'itemSorting', emberA(['fname:desc'])); assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Robb', 'Jaime', 'Cersei', 'Bran'], 'after updating sort properties array is updated' ); @@ -1269,16 +1414,18 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { let sortProps = this.obj.itemSorting; assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted' ); - sortProps.clear(); - sortProps.pushObject('fname'); + expectDeprecation(() => { + sortProps.clear(); + sortProps.pushObject('fname'); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Bran', 'Cersei', 'Jaime', 'Robb'], 'after updating sort properties array is updated' ); @@ -1286,7 +1433,7 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { ['@test updating new sort properties invalidates the sorted array'](assert) { assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted' ); @@ -1294,7 +1441,7 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { set(this.obj, 'itemSorting', emberA(['age:desc', 'fname:asc'])); assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Cersei', 'Jaime', 'Robb', 'Bran'], 'precond - array is correct after item sorting is changed' ); @@ -1302,19 +1449,22 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { set(this.obj.items[1], 'age', 29); assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Jaime', 'Cersei', 'Robb', 'Bran'], 'after updating sort properties array is updated' ); } ['@test sort direction defaults to ascending'](assert) { - assert.deepEqual(this.obj.sortedItems.mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb']); + assert.deepEqual( + this.obj.sortedItems.map((i) => i.fname), + ['Cersei', 'Jaime', 'Bran', 'Robb'] + ); } ['@test sort direction defaults to ascending (with sort property change)'](assert) { assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted' ); @@ -1322,7 +1472,7 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { set(this.obj, 'itemSorting', emberA(['fname'])); assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Bran', 'Cersei', 'Jaime', 'Robb'], 'sort direction defaults to ascending' ); @@ -1332,7 +1482,7 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { let tyrionInDisguise = this.obj.items[1]; assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted' ); @@ -1340,7 +1490,7 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { set(tyrionInDisguise, 'fname', 'Tyrion'); assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Jaime', 'Tyrion', 'Bran', 'Robb'], "updating an item's sort properties updates the sorted array" ); @@ -1350,7 +1500,7 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { let sansaInDisguise = this.obj.items[1]; assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted' ); @@ -1361,7 +1511,7 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { }); assert.deepEqual( - this.obj.sortedItems.mapBy('fname'), + this.obj.sortedItems.map((i) => i.fname), ['Jaime', 'Bran', 'Robb', 'Sansa'], "updating an item's sort properties updates the sorted array" ); @@ -1441,7 +1591,9 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { 'array is not changed' ); - this.obj.items.pushObject(12); + expectDeprecation(() => { + this.obj.items.pushObject(12); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( this.obj.sortedItems, @@ -1464,9 +1616,11 @@ class SortWithSortPropertiesTestCase extends AbstractTestCase { this.cleanupObject(); try { - sortProps.pushObject({ - name: 'Anna', - }); + expectDeprecation(() => { + sortProps.pushObject({ + name: 'Anna', + }); + }, /Usage of Ember.Array methods is deprecated/); assert.ok(true); } catch (e) { assert.ok(false, e); @@ -1541,13 +1695,17 @@ moduleFor( let itemSorting = _itemSorting || emberA(['lname', 'fname']); - return class extends EmberObject { - @sort('items', 'itemSorting') - sortedItems; - }.create({ - itemSorting, - items, - }); + let ret; + expectDeprecation(() => { + ret = class extends EmberObject { + @sort('items', 'itemSorting') + sortedItems; + }.create({ + itemSorting, + items, + }); + }, /The @sort decorator is deprecated/); + return ret; } cleanupObject() { @@ -1571,13 +1729,18 @@ moduleFor( let itemSorting = _itemSorting || emberA(['lname', 'fname']); - return new (class { - items = items; - itemSorting = itemSorting; + let ret; + expectDeprecation(() => { + ret = new (class { + items = items; + itemSorting = itemSorting; + + @sort('items', 'itemSorting') + sortedItems; + })(); + }, /The @sort decorator is deprecated/); - @sort('items', 'itemSorting') - sortedItems; - })(); + return ret; } cleanupObject() {} @@ -1609,17 +1772,19 @@ moduleFor( 'sort - sort function', class extends AbstractTestCase { beforeEach() { - obj = class extends EmberObject { - @sort('items.@each.fname', sortByLnameFname) - sortedItems; - }.create({ - items: emberA([ - { fname: 'Jaime', lname: 'Lannister', age: 34 }, - { fname: 'Cersei', lname: 'Lannister', age: 34 }, - { fname: 'Robb', lname: 'Stark', age: 16 }, - { fname: 'Bran', lname: 'Stark', age: 8 }, - ]), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @sort('items.@each.fname', sortByLnameFname) + sortedItems; + }.create({ + items: emberA([ + { fname: 'Jaime', lname: 'Lannister', age: 34 }, + { fname: 'Cersei', lname: 'Lannister', age: 34 }, + { fname: 'Robb', lname: 'Stark', age: 16 }, + { fname: 'Bran', lname: 'Stark', age: 8 }, + ]), + }); + }, /The @sort decorator is deprecated/); } afterEach() { @@ -1627,23 +1792,26 @@ moduleFor( } ['@test sort has correct `this`'](assert) { - let obj = class extends EmberObject { - @sort('items.@each.fname', function (a, b) { - assert.equal(this, obj, 'expected the object to be `this`'); - return this.sortByLastName(a, b); - }) - sortedItems; - sortByLastName(a, b) { - return sortByFnameAsc(a, b); - } - }.create({ - items: emberA([ - { fname: 'Jaime', lname: 'Lannister', age: 34 }, - { fname: 'Cersei', lname: 'Lannister', age: 34 }, - { fname: 'Robb', lname: 'Stark', age: 16 }, - { fname: 'Bran', lname: 'Stark', age: 8 }, - ]), - }); + let obj; + expectDeprecation(() => { + obj = class extends EmberObject { + @sort('items.@each.fname', function (a, b) { + assert.equal(this, obj, 'expected the object to be `this`'); + return this.sortByLastName(a, b); + }) + sortedItems; + sortByLastName(a, b) { + return sortByFnameAsc(a, b); + } + }.create({ + items: emberA([ + { fname: 'Jaime', lname: 'Lannister', age: 34 }, + { fname: 'Cersei', lname: 'Lannister', age: 34 }, + { fname: 'Robb', lname: 'Stark', age: 16 }, + { fname: 'Bran', lname: 'Stark', age: 8 }, + ]), + }); + }, /The @sort decorator is deprecated/); obj.get('sortedItems'); } @@ -1656,7 +1824,7 @@ moduleFor( ['@test arrays are initially sorted'](assert) { assert.deepEqual( - obj.get('sortedItems').mapBy('fname'), + obj.get('sortedItems').map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'array is initially sorted' ); @@ -1664,7 +1832,7 @@ moduleFor( ['@test default sort order is correct'](assert) { assert.deepEqual( - obj.get('sortedItems').mapBy('fname'), + obj.get('sortedItems').map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'array is initially sorted' ); @@ -1672,7 +1840,7 @@ moduleFor( ['@test changing the dependent array updates the sorted array'](assert) { assert.deepEqual( - obj.get('sortedItems').mapBy('fname'), + obj.get('sortedItems').map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted' ); @@ -1685,7 +1853,7 @@ moduleFor( ]); assert.deepEqual( - obj.get('sortedItems').mapBy('fname'), + obj.get('sortedItems').map((i) => i.fname), ['Stannis', 'Ramsey', 'Roose', 'Theon'], 'changing dependent array updates sorted array' ); @@ -1695,18 +1863,20 @@ moduleFor( let items = obj.get('items'); assert.deepEqual( - obj.get('sortedItems').mapBy('fname'), + obj.get('sortedItems').map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted' ); - items.pushObject({ - fname: 'Tyrion', - lname: 'Lannister', - }); + expectDeprecation(() => { + items.pushObject({ + fname: 'Tyrion', + lname: 'Lannister', + }); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( - obj.get('sortedItems').mapBy('fname'), + obj.get('sortedItems').map((i) => i.fname), ['Cersei', 'Jaime', 'Tyrion', 'Bran', 'Robb'], 'Adding to the dependent array updates the sorted array' ); @@ -1714,15 +1884,17 @@ moduleFor( ['@test removing from the dependent array updates the sorted array'](assert) { assert.deepEqual( - obj.get('sortedItems').mapBy('fname'), + obj.get('sortedItems').map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted' ); - obj.get('items').popObject(); + expectDeprecation(() => { + obj.get('items').popObject(); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( - obj.get('sortedItems').mapBy('fname'), + obj.get('sortedItems').map((i) => i.fname), ['Cersei', 'Jaime', 'Robb'], 'Removing from the dependent array updates the sorted array' ); @@ -1747,11 +1919,13 @@ moduleFor( let items = obj.get('items'); - items.replace(0, 1, [jaime]); - items.replace(1, 1, [jaimeInDisguise]); + expectDeprecation(() => { + items.replace(0, 1, [jaime]); + items.replace(1, 1, [jaimeInDisguise]); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( - obj.get('sortedItems').mapBy('fname'), + obj.get('sortedItems').map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted' ); @@ -1759,7 +1933,7 @@ moduleFor( set(jaimeInDisguise, 'fname', 'Jaime'); assert.deepEqual( - obj.get('sortedItems').mapBy('fname'), + obj.get('sortedItems').map((i) => i.fname), ['Jaime', 'Jaime', 'Bran', 'Robb'], 'sorted array is updated' ); @@ -1767,7 +1941,7 @@ moduleFor( set(jaimeInDisguise, 'fname', 'Cersei'); assert.deepEqual( - obj.get('sortedItems').mapBy('fname'), + obj.get('sortedItems').map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'sorted array is updated' ); @@ -1789,26 +1963,23 @@ moduleFor( let items = obj.get('items'); - items.pushObject(tyrion); + expectDeprecation(() => { + items.pushObject(tyrion); + }, /Usage of Ember.Array methods is deprecated/); - assert.deepEqual(obj.get('sortedItems').mapBy('fname'), [ - 'Cersei', - 'Jaime', - 'Tyrion', - 'Bran', - 'Robb', - ]); + assert.deepEqual( + obj.get('sortedItems').map((i) => i.fname), + ['Cersei', 'Jaime', 'Tyrion', 'Bran', 'Robb'] + ); - items.pushObject(tyrionInDisguise); + expectDeprecation(() => { + items.pushObject(tyrionInDisguise); + }, /Usage of Ember.Array methods is deprecated/); - assert.deepEqual(obj.get('sortedItems').mapBy('fname'), [ - 'Yollo', - 'Cersei', - 'Jaime', - 'Tyrion', - 'Bran', - 'Robb', - ]); + assert.deepEqual( + obj.get('sortedItems').map((i) => i.fname), + ['Yollo', 'Cersei', 'Jaime', 'Tyrion', 'Bran', 'Robb'] + ); } ['@test changing item properties specified via @each triggers a resort of the modified item']( @@ -1819,7 +1990,7 @@ moduleFor( let tyrionInDisguise = items[1]; assert.deepEqual( - obj.get('sortedItems').mapBy('fname'), + obj.get('sortedItems').map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted' ); @@ -1827,30 +1998,32 @@ moduleFor( set(tyrionInDisguise, 'fname', 'Tyrion'); assert.deepEqual( - obj.get('sortedItems').mapBy('fname'), + obj.get('sortedItems').map((i) => i.fname), ['Jaime', 'Tyrion', 'Bran', 'Robb'], 'updating a specified property on an item resorts it' ); } ['@test sort updates if additional dependent keys are present'](assert) { - obj = class extends EmberObject { - @sort('items', ['sortFunction'], function () { - return this.sortFunction(...arguments); - }) - sortedItems; - }.create({ - sortFunction: sortByLnameFname, - items: emberA([ - { fname: 'Jaime', lname: 'Lannister', age: 34 }, - { fname: 'Cersei', lname: 'Lannister', age: 34 }, - { fname: 'Robb', lname: 'Stark', age: 16 }, - { fname: 'Bran', lname: 'Stark', age: 8 }, - ]), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @sort('items', ['sortFunction'], function () { + return this.sortFunction(...arguments); + }) + sortedItems; + }.create({ + sortFunction: sortByLnameFname, + items: emberA([ + { fname: 'Jaime', lname: 'Lannister', age: 34 }, + { fname: 'Cersei', lname: 'Lannister', age: 34 }, + { fname: 'Robb', lname: 'Stark', age: 16 }, + { fname: 'Bran', lname: 'Stark', age: 8 }, + ]), + }); + }, /The @sort decorator is deprecated/); assert.deepEqual( - obj.get('sortedItems').mapBy('fname'), + obj.get('sortedItems').map((i) => i.fname), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'array is initially sorted' ); @@ -1866,28 +2039,30 @@ moduleFor( }); assert.deepEqual( - obj.get('sortedItems').mapBy('fname'), + obj.get('sortedItems').map((i) => i.fname), ['Jaime', 'Cersei', 'Robb', 'Bran'], 'array is updated when dependent key changes' ); } ['@test it throws on bad inputs']() { - expectAssertion(() => { - sort('foo', 'bar', 'baz'); - }, /`sort` computed macro can either be used with an array of sort properties or with a sort function/); + expectDeprecation(() => { + expectAssertion(() => { + sort('foo', 'bar', 'baz'); + }, /`sort` computed macro can either be used with an array of sort properties or with a sort function/); - expectAssertion(() => { - sort('foo', ['bar'], 'baz'); - }, /`sort` computed macro can either be used with an array of sort properties or with a sort function/); + expectAssertion(() => { + sort('foo', ['bar'], 'baz'); + }, /`sort` computed macro can either be used with an array of sort properties or with a sort function/); - expectAssertion(() => { - sort('foo', 'bar', function () {}); - }, /`sort` computed macro can either be used with an array of sort properties or with a sort function/); + expectAssertion(() => { + sort('foo', 'bar', function () {}); + }, /`sort` computed macro can either be used with an array of sort properties or with a sort function/); - expectAssertion(() => { - sort('foo', ['bar'], function () {}, 'baz'); - }, /`sort` computed macro can either be used with an array of sort properties or with a sort function/); + expectAssertion(() => { + sort('foo', ['bar'], function () {}, 'baz'); + }, /`sort` computed macro can either be used with an array of sort properties or with a sort function/); + }, /The @sort decorator is deprecated/); } } ); @@ -1896,18 +2071,20 @@ moduleFor( 'sort - stability', class extends AbstractTestCase { beforeEach() { - obj = class extends EmberObject { - sortProps = ['count', 'name']; - @sort('items', 'sortProps') - sortedItems; - }.create({ - items: [ - { name: 'A', count: 1, thing: 4 }, - { name: 'B', count: 1, thing: 3 }, - { name: 'C', count: 1, thing: 2 }, - { name: 'D', count: 1, thing: 4 }, - ], - }); + expectDeprecation(() => { + obj = class extends EmberObject { + sortProps = ['count', 'name']; + @sort('items', 'sortProps') + sortedItems; + }.create({ + items: [ + { name: 'A', count: 1, thing: 4 }, + { name: 'B', count: 1, thing: 3 }, + { name: 'C', count: 1, thing: 2 }, + { name: 'D', count: 1, thing: 4 }, + ], + }); + }, /The @sort decorator is deprecated/); } afterEach() { @@ -1915,11 +2092,19 @@ moduleFor( } ['@test sorts correctly as only one property changes'](assert) { - assert.deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'initial'); + assert.deepEqual( + obj.get('sortedItems').map((i) => i.name), + ['A', 'B', 'C', 'D'], + 'initial' + ); set(obj.get('items')[3], 'count', 2); - assert.deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'final'); + assert.deepEqual( + obj.get('sortedItems').map((i) => i.name), + ['A', 'B', 'C', 'D'], + 'final' + ); } } ); @@ -1929,13 +2114,15 @@ moduleFor( 'sort - concurrency', class extends AbstractTestCase { beforeEach() { - klass = class extends EmberObject { - sortProps = ['count']; - @sort('items', 'sortProps') - sortedItems; - @sort('items.@each.count', (a, b) => a.count - b.count) - customSortedItems; - }; + expectDeprecation(() => { + klass = class extends EmberObject { + sortProps = ['count']; + @sort('items', 'sortProps') + sortedItems; + @sort('items.@each.count', (a, b) => a.count - b.count) + customSortedItems; + }; + }, /The @sort decorator is deprecated/); obj = klass.create({ items: emberA([ { name: 'A', count: 1, thing: 4, id: 1 }, @@ -1952,23 +2139,43 @@ moduleFor( ['@test sorts correctly after mutation to the sort properties'](assert) { let sorted = obj.get('sortedItems'); - assert.deepEqual(sorted.mapBy('name'), ['A', 'B', 'C', 'D'], 'initial'); + assert.deepEqual( + sorted.map((i) => i.name), + ['A', 'B', 'C', 'D'], + 'initial' + ); set(obj.get('items')[1], 'count', 5); set(obj.get('items')[2], 'count', 6); - assert.deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'D', 'B', 'C'], 'final'); + assert.deepEqual( + obj.get('sortedItems').map((i) => i.name), + ['A', 'D', 'B', 'C'], + 'final' + ); } ['@test sort correctly after mutation to the sort'](assert) { - assert.deepEqual(obj.get('customSortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'initial'); + assert.deepEqual( + obj.get('customSortedItems').map((i) => i.name), + ['A', 'B', 'C', 'D'], + 'initial' + ); set(obj.get('items')[1], 'count', 5); set(obj.get('items')[2], 'count', 6); - assert.deepEqual(obj.get('customSortedItems').mapBy('name'), ['A', 'D', 'B', 'C'], 'final'); + assert.deepEqual( + obj.get('customSortedItems').map((i) => i.name), + ['A', 'D', 'B', 'C'], + 'final' + ); - assert.deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'D', 'B', 'C'], 'final'); + assert.deepEqual( + obj.get('sortedItems').map((i) => i.name), + ['A', 'D', 'B', 'C'], + 'final' + ); } ['@test sort correctly on multiple instances of the same class'](assert) { @@ -1981,27 +2188,53 @@ moduleFor( ]), }); - assert.deepEqual(obj2.get('sortedItems').mapBy('name'), ['W', 'X', 'Y', 'Z'], 'initial'); - assert.deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'initial'); + assert.deepEqual( + obj2.get('sortedItems').map((i) => i.name), + ['W', 'X', 'Y', 'Z'], + 'initial' + ); + assert.deepEqual( + obj.get('sortedItems').map((i) => i.name), + ['A', 'B', 'C', 'D'], + 'initial' + ); set(obj.get('items')[1], 'count', 5); set(obj.get('items')[2], 'count', 6); set(obj2.get('items')[1], 'count', 27); set(obj2.get('items')[2], 'count', 28); - assert.deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'D', 'B', 'C'], 'final'); - assert.deepEqual(obj2.get('sortedItems').mapBy('name'), ['W', 'Z', 'X', 'Y'], 'final'); + assert.deepEqual( + obj.get('sortedItems').map((i) => i.name), + ['A', 'D', 'B', 'C'], + 'final' + ); + assert.deepEqual( + obj2.get('sortedItems').map((i) => i.name), + ['W', 'Z', 'X', 'Y'], + 'final' + ); obj.set('sortProps', ['thing']); - assert.deepEqual(obj.get('sortedItems').mapBy('name'), ['D', 'C', 'B', 'A'], 'final'); + assert.deepEqual( + obj.get('sortedItems').map((i) => i.name), + ['D', 'C', 'B', 'A'], + 'final' + ); obj2.notifyPropertyChange('sortedItems'); // invalidate to flush, to get DK refreshed obj2.get('sortedItems'); // flush to get updated DK - obj2.set('items.firstObject.count', 9999); + expectDeprecation(() => { + obj2.set('items.firstObject.count', 9999); + }, /Usage of Ember.Array methods is deprecated/); - assert.deepEqual(obj2.get('sortedItems').mapBy('name'), ['Z', 'X', 'Y', 'W'], 'final'); + assert.deepEqual( + obj2.get('sortedItems').map((i) => i.name), + ['Z', 'X', 'Y', 'W'], + 'final' + ); } ['@test sort correctly when multiple sorts are chained on the same instance of a class']( @@ -2037,12 +2270,12 @@ moduleFor( */ assert.deepEqual( - obj.get('sortedItems').mapBy('name'), + obj.get('sortedItems').map((i) => i.name), ['A', 'B', 'C', 'D'], 'obj.sortedItems.name should be sorted alpha' ); assert.deepEqual( - obj2.get('sortedItems').mapBy('name'), + obj2.get('sortedItems').map((i) => i.name), ['A', 'B', 'C', 'D'], 'obj2.sortedItems.name should be sorted alpha' ); @@ -2051,12 +2284,12 @@ moduleFor( set(obj.get('items')[2], 'count', 6); assert.deepEqual( - obj.get('sortedItems').mapBy('name'), + obj.get('sortedItems').map((i) => i.name), ['A', 'D', 'B', 'C'], 'obj.sortedItems.name should now have changed' ); assert.deepEqual( - obj2.get('sortedItems').mapBy('name'), + obj2.get('sortedItems').map((i) => i.name), ['A', 'D', 'B', 'C'], 'obj2.sortedItems.name should still mirror sortedItems2' ); @@ -2065,12 +2298,12 @@ moduleFor( obj2.set('sortProps', ['id']); assert.deepEqual( - obj2.get('sortedItems').mapBy('name'), + obj2.get('sortedItems').map((i) => i.name), ['A', 'B', 'C', 'D'], 'we now sort obj2 by id, so we expect a b c d' ); assert.deepEqual( - obj.get('sortedItems').mapBy('name'), + obj.get('sortedItems').map((i) => i.name), ['D', 'C', 'B', 'A'], 'we now sort obj by thing' ); @@ -2084,12 +2317,14 @@ moduleFor( 'max', class extends AbstractTestCase { beforeEach() { - obj = class extends EmberObject { - @max('items') - max; - }.create({ - items: emberA([1, 2, 3]), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @max('items') + max; + }.create({ + items: emberA([1, 2, 3]), + }); + }, /The @max decorator is deprecated/); } afterEach() { @@ -2107,11 +2342,15 @@ moduleFor( let items = obj.get('items'); - items.pushObject(5); + expectDeprecation(() => { + items.pushObject(5); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(obj.get('max'), 5, 'max updates when a larger number is added'); - items.pushObject(2); + expectDeprecation(() => { + items.pushObject(2); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(obj.get('max'), 5, 'max does not update when a smaller number is added'); } @@ -2119,11 +2358,15 @@ moduleFor( ['@test max recomputes when the current max is removed'](assert) { assert.equal(obj.get('max'), 3, 'precond - max is initially correct'); - obj.get('items').removeObject(2); + expectDeprecation(() => { + obj.get('items').removeObject(2); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(obj.get('max'), 3, 'max is unchanged when a non-max item is removed'); - obj.get('items').removeObject(3); + expectDeprecation(() => { + obj.get('items').removeObject(3); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(obj.get('max'), 1, 'max is recomputed when the current max is removed'); } @@ -2134,12 +2377,14 @@ moduleFor( 'min', class extends AbstractTestCase { beforeEach() { - obj = class extends EmberObject { - @min('items') - min; - }.create({ - items: emberA([1, 2, 3]), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @min('items') + min; + }.create({ + items: emberA([1, 2, 3]), + }); + }, /The @min decorator is deprecated/); } afterEach() { @@ -2155,11 +2400,15 @@ moduleFor( ['@test min tracks the min number as objects are added'](assert) { assert.equal(obj.get('min'), 1, 'precond - min is initially correct'); - obj.get('items').pushObject(-2); + expectDeprecation(() => { + obj.get('items').pushObject(-2); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(obj.get('min'), -2, 'min updates when a smaller number is added'); - obj.get('items').pushObject(2); + expectDeprecation(() => { + obj.get('items').pushObject(2); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(obj.get('min'), -2, 'min does not update when a larger number is added'); } @@ -2169,11 +2418,15 @@ moduleFor( assert.equal(obj.get('min'), 1, 'precond - min is initially correct'); - items.removeObject(2); + expectDeprecation(() => { + items.removeObject(2); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(obj.get('min'), 1, 'min is unchanged when a non-min item is removed'); - items.removeObject(1); + expectDeprecation(() => { + items.removeObject(1); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(obj.get('min'), 3, 'min is recomputed when the current min is removed'); } @@ -2184,27 +2437,29 @@ moduleFor( 'Ember.arrayComputed - mixed sugar', class extends AbstractTestCase { beforeEach() { - obj = class extends EmberObject { - @filterBy('items', 'lname', 'Lannister') - lannisters; - lannisterSorting = emberA(['fname']); - @sort('lannisters', 'lannisterSorting') - sortedLannisters; - - @filterBy('items', 'lname', 'Stark') - starks; - @mapBy('starks', 'age') - starkAges; - @max('starkAges') - oldestStarkAge; - }.create({ - items: emberA([ - { fname: 'Jaime', lname: 'Lannister', age: 34 }, - { fname: 'Cersei', lname: 'Lannister', age: 34 }, - { fname: 'Robb', lname: 'Stark', age: 16 }, - { fname: 'Bran', lname: 'Stark', age: 8 }, - ]), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @filterBy('items', 'lname', 'Lannister') + lannisters; + lannisterSorting = emberA(['fname']); + @sort('lannisters', 'lannisterSorting') + sortedLannisters; + + @filterBy('items', 'lname', 'Stark') + starks; + @mapBy('starks', 'age') + starkAges; + @max('starkAges') + oldestStarkAge; + }.create({ + items: emberA([ + { fname: 'Jaime', lname: 'Lannister', age: 34 }, + { fname: 'Cersei', lname: 'Lannister', age: 34 }, + { fname: 'Robb', lname: 'Stark', age: 16 }, + { fname: 'Bran', lname: 'Stark', age: 8 }, + ]), + }); + }, /The .+ decorator is deprecated/); } afterEach() { @@ -2215,17 +2470,19 @@ moduleFor( let items = obj.get('items'); assert.deepEqual( - obj.get('sortedLannisters').mapBy('fname'), + obj.get('sortedLannisters').map((i) => i.fname), ['Cersei', 'Jaime'], 'precond - array is initially filtered and sorted' ); - items.pushObject({ fname: 'Tywin', lname: 'Lannister' }); - items.pushObject({ fname: 'Lyanna', lname: 'Stark' }); - items.pushObject({ fname: 'Gerion', lname: 'Lannister' }); + expectDeprecation(() => { + items.pushObject({ fname: 'Tywin', lname: 'Lannister' }); + items.pushObject({ fname: 'Lyanna', lname: 'Stark' }); + items.pushObject({ fname: 'Gerion', lname: 'Lannister' }); + }, /Usage of Ember.Array methods is deprecated/); assert.deepEqual( - obj.get('sortedLannisters').mapBy('fname'), + obj.get('sortedLannisters').map((i) => i.fname), ['Cersei', 'Gerion', 'Jaime', 'Tywin'], 'updates propagate to array' ); @@ -2236,11 +2493,15 @@ moduleFor( assert.equal(16, obj.get('oldestStarkAge'), 'precond - end of chain is initially correct'); - items.pushObject({ fname: 'Rickon', lname: 'Stark', age: 5 }); + expectDeprecation(() => { + items.pushObject({ fname: 'Rickon', lname: 'Stark', age: 5 }); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(16, obj.get('oldestStarkAge'), 'chain is updated correctly'); - items.pushObject({ fname: 'Eddard', lname: 'Stark', age: 35 }); + expectDeprecation(() => { + items.pushObject({ fname: 'Eddard', lname: 'Stark', age: 35 }); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(35, obj.get('oldestStarkAge'), 'chain is updated correctly'); } @@ -2268,14 +2529,16 @@ moduleFor( 'Ember.arrayComputed - chains', class extends AbstractTestCase { beforeEach() { - obj = class extends EmberObject { - @sort('todos.@each.priority', priorityComparator) - sorted; - @filter('sorted.@each.priority', evenPriorities) - filtered; - }.create({ - todos: emberA([todo('E', 4), todo('D', 3), todo('C', 2), todo('B', 1), todo('A', 0)]), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @sort('todos.@each.priority', priorityComparator) + sorted; + @filter('sorted.@each.priority', evenPriorities) + filtered; + }.create({ + todos: emberA([todo('E', 4), todo('D', 3), todo('C', 2), todo('B', 1), todo('A', 0)]), + }); + }, /The .+ decorator is deprecated/); } afterEach() { @@ -2284,17 +2547,17 @@ moduleFor( ['@test it can filter and sort when both depend on the same item property'](assert) { assert.deepEqual( - obj.get('todos').mapBy('name'), + obj.get('todos').map((i) => i.name), ['E', 'D', 'C', 'B', 'A'], 'precond - todos initially correct' ); assert.deepEqual( - obj.get('sorted').mapBy('name'), + obj.get('sorted').map((i) => i.name), ['A', 'B', 'C', 'D', 'E'], 'precond - sorted initially correct' ); assert.deepEqual( - obj.get('filtered').mapBy('name'), + obj.get('filtered').map((i) => i.name), ['A', 'C', 'E'], 'precond - filtered initially correct' ); @@ -2302,17 +2565,17 @@ moduleFor( set(obj.get('todos')[1], 'priority', 6); assert.deepEqual( - obj.get('todos').mapBy('name'), + obj.get('todos').map((i) => i.name), ['E', 'D', 'C', 'B', 'A'], 'precond - todos remain correct' ); assert.deepEqual( - obj.get('sorted').mapBy('name'), + obj.get('sorted').map((i) => i.name), ['A', 'B', 'C', 'E', 'D'], 'precond - sorted updated correctly' ); assert.deepEqual( - obj.get('filtered').mapBy('name'), + obj.get('filtered').map((i) => i.name), ['A', 'C', 'E', 'D'], 'filtered updated correctly' ); @@ -2326,16 +2589,18 @@ moduleFor( class extends AbstractTestCase { beforeEach() { userFnCalls = 0; - obj = class extends EmberObject { - @mapBy('array', 'v') - mapped; - @max('mapped') - max; - @observer('max', () => userFnCalls++) - maxDidChange; - }.create({ - array: emberA([{ v: 1 }, { v: 3 }, { v: 2 }, { v: 1 }]), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @mapBy('array', 'v') + mapped; + @max('mapped') + max; + @observer('max', () => userFnCalls++) + maxDidChange; + }.create({ + array: emberA([{ v: 1 }, { v: 3 }, { v: 2 }, { v: 1 }]), + }); + }, /The .+ decorator is deprecated/); } afterEach() { @@ -2349,7 +2614,10 @@ moduleFor( addObserver(obj, 'max', () => calls++); - obj.get('array').pushObject({ v: 5 }); + expectDeprecation(() => { + obj.get('array').pushObject({ v: 5 }); + }, /Usage of Ember.Array methods is deprecated/); + await runLoopSettled(); assert.equal(obj.get('max'), 5, 'maximum value is updated correctly'); @@ -2363,12 +2631,14 @@ moduleFor( 'sum', class extends AbstractTestCase { beforeEach() { - obj = class extends EmberObject { - @sum('array') - total; - }.create({ - array: emberA([1, 2, 3]), - }); + expectDeprecation(() => { + obj = class extends EmberObject { + @sum('array') + total; + }.create({ + array: emberA([1, 2, 3]), + }); + }, /The @sum decorator is deprecated/); } afterEach() { @@ -2397,11 +2667,15 @@ moduleFor( } ['@test updates when array is modified'](assert) { - obj.get('array').pushObject(1); + expectDeprecation(() => { + obj.get('array').pushObject(1); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(obj.get('total'), 7, 'recomputed when elements are added'); - obj.get('array').popObject(); + expectDeprecation(() => { + obj.get('array').popObject(); + }, /Usage of Ember.Array methods is deprecated/); assert.equal(obj.get('total'), 6, 'recomputes when elements are removed'); } @@ -2413,7 +2687,9 @@ moduleFor( class extends AbstractTestCase { ['@test works'](assert) { let obj = { one: 'foo', two: 'bar', three: null }; - defineProperty(obj, 'all', collect('one', 'two', 'three', 'four')); + expectDeprecation(() => { + defineProperty(obj, 'all', collect('one', 'two', 'three', 'four')); + }, /The @collect decorator is deprecated/); assert.deepEqual(get(obj, 'all'), ['foo', 'bar', null, null], 'have all of them'); diff --git a/packages/@ember/object/tests/computed_test.js b/packages/@ember/object/tests/computed_test.js index 1cccb354564..796770b6576 100644 --- a/packages/@ember/object/tests/computed_test.js +++ b/packages/@ember/object/tests/computed_test.js @@ -1,8 +1,13 @@ import { notifyPropertyChange } from '@ember/-internals/metal'; import { alias, oneWay as reads } from '@ember/object/computed'; -import { A as emberA, isArray } from '@ember/array'; +import { isArray } from '@ember/array'; import EmberObject, { defineProperty, get, set, computed, observer } from '@ember/object'; -import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; +import { + moduleFor, + emberAWithoutDeprecation as emberA, + AbstractTestCase, + expectDeprecation, +} from 'internal-test-helpers'; function K() { return this; @@ -423,13 +428,22 @@ moduleFor( n.set('options', emberA([{ value: 'foo' }])); assert.deepEqual(n.normalized, ['foo']); - n.options.pushObject({ value: 'bar' }); + expectDeprecation(() => { + n.options.pushObject({ value: 'bar' }); + }, /Usage of Ember.Array methods is deprecated/); + assert.deepEqual(n.normalized, ['foo', 'bar']); - n.options.pushObject({ extra: 'wat', value: 'baz' }); + expectDeprecation(() => { + n.options.pushObject({ extra: 'wat', value: 'baz' }); + }, /Usage of Ember.Array methods is deprecated/); + assert.deepEqual(n.normalized, ['foo', 'bar', 'baz']); - n.options.clear(); + expectDeprecation(() => { + n.options.clear(); + }, /Usage of Ember.Array methods is deprecated/); + assert.deepEqual(n.normalized, []); n.set('options', [{ value: 'foo' }, { value: 'bar' }]); diff --git a/packages/@ember/object/tests/observable_test.js b/packages/@ember/object/tests/observable_test.js index 8b6ce290204..cea5e7750a8 100644 --- a/packages/@ember/object/tests/observable_test.js +++ b/packages/@ember/object/tests/observable_test.js @@ -3,8 +3,13 @@ import { run } from '@ember/runloop'; import { get, computed } from '@ember/object'; import EmberObject, { observer } from '@ember/object'; import Observable from '@ember/object/observable'; -import { A as emberA } from '@ember/array'; -import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import { + moduleFor, + AbstractTestCase, + runLoopSettled, + emberAWithoutDeprecation as emberA, + expectDeprecation, +} from 'internal-test-helpers'; /* NOTE: This test is adapted from the 1.x series of unit tests. The tests @@ -720,7 +725,10 @@ moduleFor( } async ['@test should notify array observer when array changes'](assert) { - get(object, 'normalArray').replace(0, 0, [6]); + expectDeprecation(() => { + get(object, 'normalArray').replace(0, 0, [6]); + }, /Usage of Ember.Array methods is deprecated/); + await runLoopSettled(); assert.equal(object.abnormal, 'notifiedObserver', 'observer should be notified'); diff --git a/packages/@ember/routing/-internals.ts b/packages/@ember/routing/-internals.ts index 6c80bd96f4f..4104cbc2499 100644 --- a/packages/@ember/routing/-internals.ts +++ b/packages/@ember/routing/-internals.ts @@ -10,3 +10,4 @@ export { default as DSL, type DSLCallback } from './lib/dsl'; export type { EngineRouteInfo } from './lib/engines'; export type { RouteInfo, RouteInfoWithAttributes } from './lib/route-info'; export { default as controllerFor } from './lib/controller_for'; +export { emberAWithoutDeprecation } from './lib/array'; diff --git a/packages/@ember/routing/lib/array.ts b/packages/@ember/routing/lib/array.ts new file mode 100644 index 00000000000..6248b4657a5 --- /dev/null +++ b/packages/@ember/routing/lib/array.ts @@ -0,0 +1,14 @@ +import { disableDeprecations } from '@ember/-internals/utils/lib/mixin-deprecation'; +import { NativeArray } from '@ember/array'; +import { isEmberArray } from '@ember/array/-internals'; + +// Copy of Ember.A without the deprecation, for use just in `copyDefaultValue` +export function emberAWithoutDeprecation(this: unknown, arr?: Array): NativeArray { + if (isEmberArray(arr)) { + // SAFETY: If it's a true native array and it is also an EmberArray then it should be an Ember NativeArray + return arr as unknown as NativeArray; + } else { + // SAFETY: This will return an NativeArray but TS can't infer that. + return disableDeprecations(() => NativeArray.apply(arr ?? []) as NativeArray); + } +} diff --git a/packages/@ember/routing/route.ts b/packages/@ember/routing/route.ts index 7b4a8f24eac..debd2c2e3c3 100644 --- a/packages/@ember/routing/route.ts +++ b/packages/@ember/routing/route.ts @@ -10,7 +10,7 @@ import { getOwner } from '@ember/-internals/owner'; import type { default as BucketCache } from './lib/cache'; import EmberObject, { computed, get, set, getProperties, setProperties } from '@ember/object'; import Evented from '@ember/object/evented'; -import { A as emberA } from '@ember/array'; +import { NativeArray } from '@ember/array'; import { ActionHandler } from '@ember/-internals/runtime'; import { typeOf } from '@ember/utils'; import { isProxy, lookupDescriptor } from '@ember/-internals/utils'; @@ -36,6 +36,9 @@ import { prefixRouteNameArg, stashParamNames, } from './lib/utils'; +import { isEmberArray } from '@ember/array/-internals'; +import { disableDeprecations } from '@ember/-internals/utils/lib/mixin-deprecation'; +import { emberAWithoutDeprecation } from './-internals'; export interface ExtendedInternalRouteInfo extends InternalRouteInfo { _names?: unknown[]; @@ -1930,8 +1933,8 @@ function getQueryParamsFor(route: Route, state: RouteTransitionState): Record(value: T): T { if (Array.isArray(value)) { - // SAFETY: We lost the type data about the array if we don't cast. - return emberA(value.slice()) as unknown as T; + // SAFETY: We lose the type data about the array if we don't cast. + return emberAWithoutDeprecation(value.slice()) as unknown as T; } return value; } diff --git a/packages/@ember/routing/router.ts b/packages/@ember/routing/router.ts index a52b28f0a32..44dbc2587f4 100644 --- a/packages/@ember/routing/router.ts +++ b/packages/@ember/routing/router.ts @@ -50,6 +50,7 @@ import type { QueryParams } from 'route-recognizer'; import type { AnyFn, MethodNamesOf, OmitFirst } from '@ember/-internals/utility-types'; import type { Template } from '@glimmer/interfaces'; import type ApplicationInstance from '@ember/application/instance'; +import { emberAWithoutDeprecation } from 'internal-test-helpers'; /** @module @ember/routing/router @@ -1008,7 +1009,7 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented { } else if (defaultType === 'number') { return Number(value).valueOf(); } else if (defaultType === 'array') { - return emberA(JSON.parse(value as string)); + return emberAWithoutDeprecation(JSON.parse(value as string)); } return value; } diff --git a/packages/ember/tests/homepage_example_test.js b/packages/ember/tests/homepage_example_test.js index eb1d40b7094..dc0b3c027d3 100644 --- a/packages/ember/tests/homepage_example_test.js +++ b/packages/ember/tests/homepage_example_test.js @@ -1,8 +1,11 @@ import Route from '@ember/routing/route'; import EmberObject, { computed } from '@ember/object'; -import { A as emberA } from '@ember/array'; -import { moduleFor, ApplicationTestCase } from 'internal-test-helpers'; +import { + moduleFor, + emberAWithoutDeprecation as emberA, + ApplicationTestCase, +} from 'internal-test-helpers'; moduleFor( 'The example renders correctly', diff --git a/packages/ember/tests/routing/model_loading_test.js b/packages/ember/tests/routing/model_loading_test.js index 89cdd281220..77771047f24 100644 --- a/packages/ember/tests/routing/model_loading_test.js +++ b/packages/ember/tests/routing/model_loading_test.js @@ -2,8 +2,12 @@ import Route from '@ember/routing/route'; import Controller from '@ember/controller'; import EmberObject from '@ember/object'; -import { A as emberA } from '@ember/array'; -import { moduleFor, ApplicationTestCase, getTextOf } from 'internal-test-helpers'; +import { + moduleFor, + ApplicationTestCase, + getTextOf, + emberAWithoutDeprecation as emberA, +} from 'internal-test-helpers'; import { run } from '@ember/runloop'; import { action, computed, set } from '@ember/object'; import { service } from '@ember/service'; diff --git a/packages/ember/tests/routing/query_params_test.js b/packages/ember/tests/routing/query_params_test.js index d9f33febc3d..3cbdb170980 100644 --- a/packages/ember/tests/routing/query_params_test.js +++ b/packages/ember/tests/routing/query_params_test.js @@ -2,7 +2,6 @@ import Controller from '@ember/controller'; import { dasherize } from '@ember/-internals/string'; import EmberObject, { action, get, computed } from '@ember/object'; import { RSVP } from '@ember/-internals/runtime'; -import { A as emberA } from '@ember/array'; import { run } from '@ember/runloop'; import { peekMeta } from '@ember/-internals/meta'; import { tracked } from '@ember/-internals/metal'; @@ -10,7 +9,14 @@ import Route from '@ember/routing/route'; import { PARAMS_SYMBOL } from 'router_js'; import { service } from '@ember/service'; -import { QueryParamTestCase, moduleFor, getTextOf, runLoopSettled } from 'internal-test-helpers'; +import { + QueryParamTestCase, + moduleFor, + getTextOf, + runLoopSettled, + emberAWithoutDeprecation as emberA, + expectDeprecation, +} from 'internal-test-helpers'; moduleFor( 'Query Params - main', @@ -1294,7 +1300,7 @@ moduleFor( } async ['@test Array query params can be pushed/popped'](assert) { - assert.expect(17); + assert.expect(25); this.router.map(function () { this.route('home', { path: '/' }); @@ -1305,42 +1311,66 @@ moduleFor( await this.visitAndAssert('/'); let controller = this.getController('home'); - controller.foo.pushObject(1); + expectDeprecation(() => { + controller.foo.pushObject(1); + }, /Usage of Ember.Array methods is deprecated/); + await runLoopSettled(); this.assertCurrentPath('/?foo=%5B1%5D'); assert.deepEqual(controller.foo, [1]); - controller.foo.popObject(); + expectDeprecation(() => { + controller.foo.popObject(); + }, /Usage of Ember.Array methods is deprecated/); + await runLoopSettled(); this.assertCurrentPath('/'); assert.deepEqual(controller.foo, []); - controller.foo.pushObject(1); + expectDeprecation(() => { + controller.foo.pushObject(1); + }, /Usage of Ember.Array methods is deprecated/); + await runLoopSettled(); this.assertCurrentPath('/?foo=%5B1%5D'); assert.deepEqual(controller.foo, [1]); - controller.foo.popObject(); + expectDeprecation(() => { + controller.foo.popObject(); + }, /Usage of Ember.Array methods is deprecated/); + await runLoopSettled(); this.assertCurrentPath('/'); assert.deepEqual(controller.foo, []); - controller.foo.pushObject(1); + expectDeprecation(() => { + controller.foo.pushObject(1); + }, /Usage of Ember.Array methods is deprecated/); + await runLoopSettled(); this.assertCurrentPath('/?foo=%5B1%5D'); assert.deepEqual(controller.foo, [1]); - controller.foo.pushObject(2); + expectDeprecation(() => { + controller.foo.pushObject(2); + }, /Usage of Ember.Array methods is deprecated/); + await runLoopSettled(); this.assertCurrentPath('/?foo=%5B1%2C2%5D'); assert.deepEqual(controller.foo, [1, 2]); - controller.foo.popObject(); + expectDeprecation(() => { + controller.foo.popObject(); + }, /Usage of Ember.Array methods is deprecated/); + await runLoopSettled(); this.assertCurrentPath('/?foo=%5B1%5D'); assert.deepEqual(controller.foo, [1]); - controller.foo.unshiftObject('lol'); + expectDeprecation(() => { + controller.foo.unshiftObject('lol'); + }, /Usage of Ember.Array methods is deprecated/); + await runLoopSettled(); this.assertCurrentPath('/?foo=%5B%22lol%22%2C1%5D'); assert.deepEqual(controller.foo, ['lol', 1]); diff --git a/packages/ember/tests/routing/query_params_test/model_dependent_state_with_query_params_test.js b/packages/ember/tests/routing/query_params_test/model_dependent_state_with_query_params_test.js index 0b72baeaa12..218c99f8e1d 100644 --- a/packages/ember/tests/routing/query_params_test/model_dependent_state_with_query_params_test.js +++ b/packages/ember/tests/routing/query_params_test/model_dependent_state_with_query_params_test.js @@ -1,8 +1,12 @@ import Controller from '@ember/controller'; -import { A as emberA } from '@ember/array'; import Route from '@ember/routing/route'; import { computed } from '@ember/object'; -import { QueryParamTestCase, moduleFor, runLoopSettled } from 'internal-test-helpers'; +import { + QueryParamTestCase, + moduleFor, + runLoopSettled, + emberAWithoutDeprecation as emberA, +} from 'internal-test-helpers'; class ModelDependentQPTestCase extends QueryParamTestCase { boot() { @@ -317,7 +321,7 @@ moduleFor( ); self.expectedModelHookParams = null; } - return articles.findBy('id', params.id); + return articles.find((i) => i.id === params.id); } } ); @@ -428,7 +432,7 @@ moduleFor( ); self.expectedModelHookParams = null; } - return site_articles.findBy('id', params.id); + return site_articles.find((i) => i.id === params.id); } } ); @@ -558,7 +562,7 @@ moduleFor( ); self.expectedSiteModelHookParams = null; } - return sites.findBy('id', params.site_id); + return sites.find((i) => i.id === params.site_id); } } ); @@ -575,7 +579,7 @@ moduleFor( ); self.expectedArticleModelHookParams = null; } - return site_articles.findBy('id', params.article_id); + return site_articles.find((i) => i.id === params.article_id); } } ); diff --git a/packages/ember/tests/routing/template_rendering_test.js b/packages/ember/tests/routing/template_rendering_test.js index 069b5e9ebe9..f64de515b7c 100644 --- a/packages/ember/tests/routing/template_rendering_test.js +++ b/packages/ember/tests/routing/template_rendering_test.js @@ -2,8 +2,12 @@ import Route from '@ember/routing/route'; import Controller from '@ember/controller'; import EmberObject from '@ember/object'; -import { A as emberA } from '@ember/array'; -import { moduleFor, ApplicationTestCase, getTextOf } from 'internal-test-helpers'; +import { + moduleFor, + ApplicationTestCase, + getTextOf, + emberAWithoutDeprecation as emberA, +} from 'internal-test-helpers'; import { run } from '@ember/runloop'; import { Component } from '@ember/-internals/glimmer'; import { service } from '@ember/service'; diff --git a/packages/internal-test-helpers/index.ts b/packages/internal-test-helpers/index.ts index 33c768572fa..a181db99985 100644 --- a/packages/internal-test-helpers/index.ts +++ b/packages/internal-test-helpers/index.ts @@ -59,3 +59,4 @@ export { export { isEdge } from './lib/browser-detect'; export { verifyRegistration } from './lib/registry-check'; +export { emberAWithoutDeprecation } from './lib/array'; diff --git a/packages/internal-test-helpers/lib/array.ts b/packages/internal-test-helpers/lib/array.ts new file mode 100644 index 00000000000..5c29183fd16 --- /dev/null +++ b/packages/internal-test-helpers/lib/array.ts @@ -0,0 +1,14 @@ +import { NativeArray } from '@ember/array'; +import { isEmberArray } from '@ember/array/-internals'; +import { disableDeprecations } from '@ember/-internals/utils/lib/mixin-deprecation'; + +// Copy of Ember.A without the deprecation, for use here since it's hard to trap deprecations in some places in this test. +export function emberAWithoutDeprecation(this: unknown, arr?: Array) { + if (isEmberArray(arr)) { + // SAFETY: If it's a true native array and it is also an EmberArray then it should be an Ember NativeArray + return arr as unknown as NativeArray; + } else { + // SAFETY: This will return an NativeArray but TS can't infer that. + return disableDeprecations(() => NativeArray.apply(arr ?? []) as NativeArray); + } +}