diff --git a/packages/ember-metal/tests/watching/is_watching_test.js b/packages/ember-metal/tests/watching/is_watching_test.js index 7d15b937bae..5ced6198d08 100644 --- a/packages/ember-metal/tests/watching/is_watching_test.js +++ b/packages/ember-metal/tests/watching/is_watching_test.js @@ -8,8 +8,7 @@ import { removeObserver, isWatching } from '../..'; - -QUnit.module('isWatching'); +import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; function testObserver(assert, setup, teardown, key = 'key') { let obj = {}; @@ -22,47 +21,50 @@ function testObserver(assert, setup, teardown, key = 'key') { assert.equal(isWatching(obj, key), false, 'isWatching is false after observers are removed'); } -QUnit.test('isWatching is true for regular local observers', function(assert) { - testObserver(assert, (obj, key, fn) => { - Mixin.create({ - didChange: observer(key, fn) - }).apply(obj); - }, (obj, key, fn) => removeObserver(obj, key, obj, fn)); -}); +moduleFor('isWatching', class extends AbstractTestCase { + ['@test isWatching is true for regular local observers'](assert) { + testObserver(assert, (obj, key, fn) => { + Mixin.create({ + didChange: observer(key, fn) + }).apply(obj); + }, (obj, key, fn) => removeObserver(obj, key, obj, fn)); + } -QUnit.test('isWatching is true for nonlocal observers', function(assert) { - testObserver(assert, (obj, key, fn) => { - addObserver(obj, key, obj, fn); - }, (obj, key, fn) => removeObserver(obj, key, obj, fn)); -}); + ['@test isWatching is true for nonlocal observers'](assert) { + testObserver(assert, (obj, key, fn) => { + addObserver(obj, key, obj, fn); + }, (obj, key, fn) => removeObserver(obj, key, obj, fn)); + } -QUnit.test('isWatching is true for chained observers', function(assert) { - testObserver(assert, function(obj, key, fn) { - addObserver(obj, key + '.bar', obj, fn); - }, function(obj, key, fn) { - removeObserver(obj, key + '.bar', obj, fn); - }); -}); + ['@test isWatching is true for chained observers'](assert) { + testObserver(assert, function(obj, key, fn) { + addObserver(obj, key + '.bar', obj, fn); + }, function(obj, key, fn) { + removeObserver(obj, key + '.bar', obj, fn); + }); + } -QUnit.test('isWatching is true for computed properties', function(assert) { - testObserver(assert, (obj, key, fn) => { - defineProperty(obj, 'computed', computed(fn).property(key)); - get(obj, 'computed'); - }, obj => defineProperty(obj, 'computed', null)); -}); + ['@test isWatching is true for computed properties'](assert) { + testObserver(assert, (obj, key, fn) => { + defineProperty(obj, 'computed', computed(fn).property(key)); + get(obj, 'computed'); + }, obj => defineProperty(obj, 'computed', null)); + } -QUnit.test('isWatching is true for chained computed properties', function(assert) { - testObserver(assert, (obj, key, fn) => { - defineProperty(obj, 'computed', computed(fn).property(key + '.bar')); - get(obj, 'computed'); - }, obj => defineProperty(obj, 'computed', null)); -}); + ['@test isWatching is true for chained computed properties'](assert) { + testObserver(assert, (obj, key, fn) => { + defineProperty(obj, 'computed', computed(fn).property(key + '.bar')); + get(obj, 'computed'); + }, obj => defineProperty(obj, 'computed', null)); + } -// can't watch length on Array - it is special... -// But you should be able to watch a length property of an object -QUnit.test('isWatching is true for \'length\' property on object', function(assert) { - testObserver(assert, (obj, key, fn) => { - defineProperty(obj, 'length', null, '26.2 miles'); - addObserver(obj, 'length', obj, fn); - }, (obj, key, fn) => removeObserver(obj, 'length', obj, fn), 'length'); + // can't watch length on Array - it is special... + // But you should be able to watch a length property of an object + ['@test isWatching is true for \'length\' property on object'](assert) { + testObserver(assert, (obj, key, fn) => { + defineProperty(obj, 'length', null, '26.2 miles'); + addObserver(obj, 'length', obj, fn); + }, (obj, key, fn) => removeObserver(obj, 'length', obj, fn), 'length'); + } }); + diff --git a/packages/ember-metal/tests/watching/unwatch_test.js b/packages/ember-metal/tests/watching/unwatch_test.js index 26138e0f110..b241be93dd6 100644 --- a/packages/ember-metal/tests/watching/unwatch_test.js +++ b/packages/ember-metal/tests/watching/unwatch_test.js @@ -1,4 +1,3 @@ -import { testBoth } from 'internal-test-helpers'; import { watch, unwatch, @@ -7,110 +6,114 @@ import { computed, set } from '../..'; +import { + moduleFor, + AbstractTestCase +} from 'internal-test-helpers'; let willCount, didCount; -QUnit.module('unwatch', { - beforeEach() { - willCount = didCount = 0; - } -}); - function addListeners(obj, keyPath) { addListener(obj, keyPath + ':before', () => willCount++); addListener(obj, keyPath + ':change', () => didCount++); } -testBoth('unwatching a computed property - regular get/set', function(get, set, assert) { - let obj = {}; - - defineProperty(obj, 'foo', computed({ - get() { - return this.__foo; - }, - set(keyName, value) { - this.__foo = value; - return this.__foo; - } - })); - addListeners(obj, 'foo'); - - watch(obj, 'foo'); - set(obj, 'foo', 'bar'); - assert.equal(willCount, 1, 'should have invoked willCount'); - assert.equal(didCount, 1, 'should have invoked didCount'); - - unwatch(obj, 'foo'); - willCount = didCount = 0; - set(obj, 'foo', 'BAZ'); - assert.equal(willCount, 0, 'should NOT have invoked willCount'); - assert.equal(didCount, 0, 'should NOT have invoked didCount'); -}); +moduleFor('unwatch', class extends AbstractTestCase { + beforeEach() { + willCount = didCount = 0; + } + ['@test unwatching a computed property - regular get/set'](assert) { + let obj = {}; + + defineProperty(obj, 'foo', computed({ + get() { + return this.__foo; + }, + set(keyName, value) { + this.__foo = value; + return this.__foo; + } + })); + addListeners(obj, 'foo'); + + watch(obj, 'foo'); + set(obj, 'foo', 'bar'); + assert.equal(willCount, 1, 'should have invoked willCount'); + assert.equal(didCount, 1, 'should have invoked didCount'); + + unwatch(obj, 'foo'); + willCount = didCount = 0; + set(obj, 'foo', 'BAZ'); + assert.equal(willCount, 0, 'should NOT have invoked willCount'); + assert.equal(didCount, 0, 'should NOT have invoked didCount'); + } -testBoth('unwatching a regular property - regular get/set', function(get, set, assert) { - let obj = { foo: 'BIFF' }; - addListeners(obj, 'foo'); + ['@test unwatching a regular property - regular get/set'](assert) { + let obj = { foo: 'BIFF' }; + addListeners(obj, 'foo'); - watch(obj, 'foo'); - set(obj, 'foo', 'bar'); - assert.equal(willCount, 1, 'should have invoked willCount'); - assert.equal(didCount, 1, 'should have invoked didCount'); + watch(obj, 'foo'); + set(obj, 'foo', 'bar'); + assert.equal(willCount, 1, 'should have invoked willCount'); + assert.equal(didCount, 1, 'should have invoked didCount'); - unwatch(obj, 'foo'); - willCount = didCount = 0; - set(obj, 'foo', 'BAZ'); - assert.equal(willCount, 0, 'should NOT have invoked willCount'); - assert.equal(didCount, 0, 'should NOT have invoked didCount'); -}); + unwatch(obj, 'foo'); + willCount = didCount = 0; + set(obj, 'foo', 'BAZ'); + assert.equal(willCount, 0, 'should NOT have invoked willCount'); + assert.equal(didCount, 0, 'should NOT have invoked didCount'); + } -QUnit.test('unwatching should be nested', function(assert) { - let obj = { foo: 'BIFF' }; - addListeners(obj, 'foo'); - - watch(obj, 'foo'); - watch(obj, 'foo'); - set(obj, 'foo', 'bar'); - assert.equal(willCount, 1, 'should have invoked willCount'); - assert.equal(didCount, 1, 'should have invoked didCount'); - - unwatch(obj, 'foo'); - willCount = didCount = 0; - set(obj, 'foo', 'BAZ'); - assert.equal(willCount, 1, 'should NOT have invoked willCount'); - assert.equal(didCount, 1, 'should NOT have invoked didCount'); - - unwatch(obj, 'foo'); - willCount = didCount = 0; - set(obj, 'foo', 'BAZ'); - assert.equal(willCount, 0, 'should NOT have invoked willCount'); - assert.equal(didCount, 0, 'should NOT have invoked didCount'); -}); + ['@test unwatching should be nested'](assert) { + let obj = { foo: 'BIFF' }; + addListeners(obj, 'foo'); -testBoth('unwatching "length" property on an object', function(get, set, assert) { - let obj = { foo: 'RUN' }; - addListeners(obj, 'length'); - - // Can watch length when it is undefined - watch(obj, 'length'); - set(obj, 'length', '10k'); - assert.equal(willCount, 1, 'should have invoked willCount'); - assert.equal(didCount, 1, 'should have invoked didCount'); - - // Should stop watching despite length now being defined (making object 'array-like') - unwatch(obj, 'length'); - willCount = didCount = 0; - set(obj, 'length', '5k'); - assert.equal(willCount, 0, 'should NOT have invoked willCount'); - assert.equal(didCount, 0, 'should NOT have invoked didCount'); -}); + watch(obj, 'foo'); + watch(obj, 'foo'); + set(obj, 'foo', 'bar'); + assert.equal(willCount, 1, 'should have invoked willCount'); + assert.equal(didCount, 1, 'should have invoked didCount'); + + unwatch(obj, 'foo'); + willCount = didCount = 0; + set(obj, 'foo', 'BAZ'); + assert.equal(willCount, 1, 'should NOT have invoked willCount'); + assert.equal(didCount, 1, 'should NOT have invoked didCount'); + + unwatch(obj, 'foo'); + willCount = didCount = 0; + set(obj, 'foo', 'BAZ'); + assert.equal(willCount, 0, 'should NOT have invoked willCount'); + assert.equal(didCount, 0, 'should NOT have invoked didCount'); + } -testBoth('unwatching should not destroy non MANDATORY_SETTER descriptor', function(get, set, assert) { - let obj = { get foo() { return 'RUN'; } }; + ['@test unwatching "length" property on an object'](assert) { + let obj = { foo: 'RUN' }; + addListeners(obj, 'length'); - assert.equal(obj.foo, 'RUN', 'obj.foo'); - watch(obj, 'foo'); - assert.equal(obj.foo, 'RUN', 'obj.foo after watch'); - unwatch(obj, 'foo'); - assert.equal(obj.foo, 'RUN', 'obj.foo after unwatch'); + // Can watch length when it is undefined + watch(obj, 'length'); + set(obj, 'length', '10k'); + assert.equal(willCount, 1, 'should have invoked willCount'); + assert.equal(didCount, 1, 'should have invoked didCount'); + + // Should stop watching despite length now being defined (making object 'array-like') + unwatch(obj, 'length'); + willCount = didCount = 0; + set(obj, 'length', '5k'); + assert.equal(willCount, 0, 'should NOT have invoked willCount'); + assert.equal(didCount, 0, 'should NOT have invoked didCount'); + } + + ['@test unwatching should not destroy non MANDATORY_SETTER descriptor'](assert) { + let obj = { get foo() { return 'RUN'; } }; + + assert.equal(obj.foo, 'RUN', 'obj.foo'); + watch(obj, 'foo'); + assert.equal(obj.foo, 'RUN', 'obj.foo after watch'); + unwatch(obj, 'foo'); + assert.equal(obj.foo, 'RUN', 'obj.foo after unwatch'); + } }); + diff --git a/packages/ember-metal/tests/watching/watch_test.js b/packages/ember-metal/tests/watching/watch_test.js index f6752f3e9d3..7a55c1b3287 100644 --- a/packages/ember-metal/tests/watching/watch_test.js +++ b/packages/ember-metal/tests/watching/watch_test.js @@ -10,11 +10,25 @@ import { unwatch, deleteMeta } from '../..'; -import { testBoth } from 'internal-test-helpers'; +import { + moduleFor, + AbstractTestCase +} from 'internal-test-helpers'; let willCount, didCount, willKeys, didKeys, originalLookup; -QUnit.module('watch', { +function addListeners(obj, keyPath) { + addListener(obj, keyPath + ':before', function() { + willCount++; + willKeys.push(keyPath); + }); + addListener(obj, keyPath + ':change', function() { + didCount++; + didKeys.push(keyPath); + }); +} + +moduleFor('watch', class extends AbstractTestCase { beforeEach() { willCount = didCount = 0; willKeys = []; @@ -22,234 +36,224 @@ QUnit.module('watch', { originalLookup = context.lookup; context.lookup = {}; - }, + } afterEach() { context.lookup = originalLookup; } -}); -function addListeners(obj, keyPath) { - addListener(obj, keyPath + ':before', function() { - willCount++; - willKeys.push(keyPath); - }); - addListener(obj, keyPath + ':change', function() { - didCount++; - didKeys.push(keyPath); - }); -} - -testBoth('watching a computed property', function(get, set, assert) { - let obj = {}; - defineProperty(obj, 'foo', computed({ - get() { - return this.__foo; - }, - set(keyName, value) { - if (value !== undefined) { - this.__foo = value; + ['@test watching a computed property'](assert) { + let obj = {}; + defineProperty(obj, 'foo', computed({ + get() { + return this.__foo; + }, + set(keyName, value) { + if (value !== undefined) { + this.__foo = value; + } + return this.__foo; } - return this.__foo; - } - })); - addListeners(obj, 'foo'); - - watch(obj, 'foo'); - set(obj, 'foo', 'bar'); - assert.equal(willCount, 1, 'should have invoked willCount'); - assert.equal(didCount, 1, 'should have invoked didCount'); -}); + })); + addListeners(obj, 'foo'); -testBoth('watching a regular defined property', function(get, set, assert) { - let obj = { foo: 'baz' }; - addListeners(obj, 'foo'); + watch(obj, 'foo'); + set(obj, 'foo', 'bar'); + assert.equal(willCount, 1, 'should have invoked willCount'); + assert.equal(didCount, 1, 'should have invoked didCount'); + } - watch(obj, 'foo'); - assert.equal(get(obj, 'foo'), 'baz', 'should have original prop'); + ['@test watching a regular defined property'](assert) { + let obj = { foo: 'baz' }; + addListeners(obj, 'foo'); - set(obj, 'foo', 'bar'); - assert.equal(willCount, 1, 'should have invoked willCount'); - assert.equal(didCount, 1, 'should have invoked didCount'); + watch(obj, 'foo'); + assert.equal(get(obj, 'foo'), 'baz', 'should have original prop'); - assert.equal(get(obj, 'foo'), 'bar', 'should get new value'); - assert.equal(obj.foo, 'bar', 'property should be accessible on obj'); -}); + set(obj, 'foo', 'bar'); + assert.equal(willCount, 1, 'should have invoked willCount'); + assert.equal(didCount, 1, 'should have invoked didCount'); -testBoth('watching a regular undefined property', function(get, set, assert) { - let obj = { }; - addListeners(obj, 'foo'); + assert.equal(get(obj, 'foo'), 'bar', 'should get new value'); + assert.equal(obj.foo, 'bar', 'property should be accessible on obj'); + } - watch(obj, 'foo'); + ['@test watching a regular undefined property'](assert) { + let obj = { }; + addListeners(obj, 'foo'); - assert.equal('foo' in obj, false, 'precond undefined'); + watch(obj, 'foo'); - set(obj, 'foo', 'bar'); + assert.equal('foo' in obj, false, 'precond undefined'); - assert.equal(willCount, 1, 'should have invoked willCount'); - assert.equal(didCount, 1, 'should have invoked didCount'); + set(obj, 'foo', 'bar'); - assert.equal(get(obj, 'foo'), 'bar', 'should get new value'); - assert.equal(obj.foo, 'bar', 'property should be accessible on obj'); -}); + assert.equal(willCount, 1, 'should have invoked willCount'); + assert.equal(didCount, 1, 'should have invoked didCount'); -testBoth('watches should inherit', function(get, set, assert) { - let obj = { foo: 'baz' }; - let objB = Object.create(obj); + assert.equal(get(obj, 'foo'), 'bar', 'should get new value'); + assert.equal(obj.foo, 'bar', 'property should be accessible on obj'); + } - addListeners(obj, 'foo'); - watch(obj, 'foo'); - assert.equal(get(obj, 'foo'), 'baz', 'should have original prop'); + ['@test watches should inherit'](assert) { + let obj = { foo: 'baz' }; + let objB = Object.create(obj); - set(obj, 'foo', 'bar'); - set(objB, 'foo', 'baz'); - assert.equal(willCount, 2, 'should have invoked willCount once only'); - assert.equal(didCount, 2, 'should have invoked didCount once only'); -}); + addListeners(obj, 'foo'); + watch(obj, 'foo'); + assert.equal(get(obj, 'foo'), 'baz', 'should have original prop'); -QUnit.test('watching an object THEN defining it should work also', function(assert) { - let obj = {}; - addListeners(obj, 'foo'); + set(obj, 'foo', 'bar'); + set(objB, 'foo', 'baz'); + assert.equal(willCount, 2, 'should have invoked willCount once only'); + assert.equal(didCount, 2, 'should have invoked didCount once only'); + } - watch(obj, 'foo'); + ['@test watching an object THEN defining it should work also'](assert) { + let obj = {}; + addListeners(obj, 'foo'); - defineProperty(obj, 'foo'); - set(obj, 'foo', 'bar'); + watch(obj, 'foo'); - assert.equal(get(obj, 'foo'), 'bar', 'should have set'); - assert.equal(willCount, 1, 'should have invoked willChange once'); - assert.equal(didCount, 1, 'should have invoked didChange once'); -}); + defineProperty(obj, 'foo'); + set(obj, 'foo', 'bar'); -QUnit.test('watching a chain then defining the property', function(assert) { - let obj = {}; - let foo = { bar: 'bar' }; - addListeners(obj, 'foo.bar'); - addListeners(foo, 'bar'); + assert.equal(get(obj, 'foo'), 'bar', 'should have set'); + assert.equal(willCount, 1, 'should have invoked willChange once'); + assert.equal(didCount, 1, 'should have invoked didChange once'); + } - watch(obj, 'foo.bar'); + ['@test watching a chain then defining the property'](assert) { + let obj = {}; + let foo = { bar: 'bar' }; + addListeners(obj, 'foo.bar'); + addListeners(foo, 'bar'); - defineProperty(obj, 'foo', undefined, foo); - set(foo, 'bar', 'baz'); + watch(obj, 'foo.bar'); - assert.deepEqual(willKeys, ['foo.bar', 'bar'], 'should have invoked willChange with bar, foo.bar'); - assert.deepEqual(didKeys, ['foo.bar', 'bar'], 'should have invoked didChange with bar, foo.bar'); - assert.equal(willCount, 2, 'should have invoked willChange twice'); - assert.equal(didCount, 2, 'should have invoked didChange twice'); -}); + defineProperty(obj, 'foo', undefined, foo); + set(foo, 'bar', 'baz'); -QUnit.test('watching a chain then defining the nested property', function(assert) { - let bar = {}; - let obj = { foo: bar }; - let baz = { baz: 'baz' }; - addListeners(obj, 'foo.bar.baz'); - addListeners(baz, 'baz'); + assert.deepEqual(willKeys, ['foo.bar', 'bar'], 'should have invoked willChange with bar, foo.bar'); + assert.deepEqual(didKeys, ['foo.bar', 'bar'], 'should have invoked didChange with bar, foo.bar'); + assert.equal(willCount, 2, 'should have invoked willChange twice'); + assert.equal(didCount, 2, 'should have invoked didChange twice'); + } - watch(obj, 'foo.bar.baz'); + ['@test watching a chain then defining the nested property'](assert) { + let bar = {}; + let obj = { foo: bar }; + let baz = { baz: 'baz' }; + addListeners(obj, 'foo.bar.baz'); + addListeners(baz, 'baz'); - defineProperty(bar, 'bar', undefined, baz); - set(baz, 'baz', 'BOO'); + watch(obj, 'foo.bar.baz'); - assert.deepEqual(willKeys, ['foo.bar.baz', 'baz'], 'should have invoked willChange with bar, foo.bar'); - assert.deepEqual(didKeys, ['foo.bar.baz', 'baz'], 'should have invoked didChange with bar, foo.bar'); - assert.equal(willCount, 2, 'should have invoked willChange twice'); - assert.equal(didCount, 2, 'should have invoked didChange twice'); -}); + defineProperty(bar, 'bar', undefined, baz); + set(baz, 'baz', 'BOO'); -testBoth('watching an object value then unwatching should restore old value', function(get, set, assert) { - let obj = { foo: { bar: { baz: { biff: 'BIFF' } } } }; - addListeners(obj, 'foo.bar.baz.biff'); + assert.deepEqual(willKeys, ['foo.bar.baz', 'baz'], 'should have invoked willChange with bar, foo.bar'); + assert.deepEqual(didKeys, ['foo.bar.baz', 'baz'], 'should have invoked didChange with bar, foo.bar'); + assert.equal(willCount, 2, 'should have invoked willChange twice'); + assert.equal(didCount, 2, 'should have invoked didChange twice'); + } - watch(obj, 'foo.bar.baz.biff'); + ['@test watching an object value then unwatching should restore old value'](assert) { + let obj = { foo: { bar: { baz: { biff: 'BIFF' } } } }; + addListeners(obj, 'foo.bar.baz.biff'); - let foo = get(obj, 'foo'); - assert.equal(get(get(get(foo, 'bar'), 'baz'), 'biff'), 'BIFF', 'biff should exist'); + watch(obj, 'foo.bar.baz.biff'); - unwatch(obj, 'foo.bar.baz.biff'); - assert.equal(get(get(get(foo, 'bar'), 'baz'), 'biff'), 'BIFF', 'biff should exist'); -}); + let foo = get(obj, 'foo'); + assert.equal(get(get(get(foo, 'bar'), 'baz'), 'biff'), 'BIFF', 'biff should exist'); -QUnit.test('when watching another object, destroy should remove chain watchers from the other object', function(assert) { - let objA = {}; - let objB = { foo: 'bar' }; - objA.b = objB; - addListeners(objA, 'b.foo'); + unwatch(obj, 'foo.bar.baz.biff'); + assert.equal(get(get(get(foo, 'bar'), 'baz'), 'biff'), 'BIFF', 'biff should exist'); + } - watch(objA, 'b.foo'); + ['@test when watching another object, destroy should remove chain watchers from the other object'](assert) { + let objA = {}; + let objB = { foo: 'bar' }; + objA.b = objB; + addListeners(objA, 'b.foo'); - let meta_objB = meta(objB); - let chainNode = meta(objA).readableChains()._chains.b._chains.foo; + watch(objA, 'b.foo'); - assert.equal(meta_objB.peekWatching('foo'), 1, 'should be watching foo'); - assert.equal(meta_objB.readableChainWatchers().has('foo', chainNode), true, 'should have chain watcher'); + let meta_objB = meta(objB); + let chainNode = meta(objA).readableChains()._chains.b._chains.foo; - deleteMeta(objA); + assert.equal(meta_objB.peekWatching('foo'), 1, 'should be watching foo'); + assert.equal(meta_objB.readableChainWatchers().has('foo', chainNode), true, 'should have chain watcher'); - assert.equal(meta_objB.peekWatching('foo'), 0, 'should not be watching foo'); - assert.equal(meta_objB.readableChainWatchers().has('foo', chainNode), false, 'should not have chain watcher'); -}); + deleteMeta(objA); -// TESTS for length property + assert.equal(meta_objB.peekWatching('foo'), 0, 'should not be watching foo'); + assert.equal(meta_objB.readableChainWatchers().has('foo', chainNode), false, 'should not have chain watcher'); + } -testBoth('watching "length" property on an object', function(get, set, assert) { - let obj = { length: '26.2 miles' }; - addListeners(obj, 'length'); + // TESTS for length property - watch(obj, 'length'); - assert.equal(get(obj, 'length'), '26.2 miles', 'should have original prop'); + ['@test watching "length" property on an object'](assert) { + let obj = { length: '26.2 miles' }; + addListeners(obj, 'length'); - set(obj, 'length', '10k'); - assert.equal(willCount, 1, 'should have invoked willCount'); - assert.equal(didCount, 1, 'should have invoked didCount'); + watch(obj, 'length'); + assert.equal(get(obj, 'length'), '26.2 miles', 'should have original prop'); - assert.equal(get(obj, 'length'), '10k', 'should get new value'); - assert.equal(obj.length, '10k', 'property should be accessible on obj'); -}); + set(obj, 'length', '10k'); + assert.equal(willCount, 1, 'should have invoked willCount'); + assert.equal(didCount, 1, 'should have invoked didCount'); -testBoth('watching "length" property on an array', function(get, set, assert) { - let arr = []; - addListeners(arr, 'length'); + assert.equal(get(obj, 'length'), '10k', 'should get new value'); + assert.equal(obj.length, '10k', 'property should be accessible on obj'); + } - watch(arr, 'length'); - assert.equal(get(arr, 'length'), 0, 'should have original prop'); + ['@test watching "length" property on an array'](assert) { + let arr = []; + addListeners(arr, 'length'); - set(arr, 'length', '10'); - assert.equal(willCount, 1, 'should NOT have invoked willCount'); - assert.equal(didCount, 1, 'should NOT have invoked didCount'); + watch(arr, 'length'); + assert.equal(get(arr, 'length'), 0, 'should have original prop'); - assert.equal(get(arr, 'length'), 10, 'should get new value'); - assert.equal(arr.length, 10, 'property should be accessible on arr'); -}); + set(arr, 'length', '10'); + assert.equal(willCount, 1, 'should NOT have invoked willCount'); + assert.equal(didCount, 1, 'should NOT have invoked didCount'); -testBoth('watch + ES5 getter', function(get, set, assert) { - let parent = { b: 1 }; - let child = { - get b() { - return parent.b; - } - }; + assert.equal(get(arr, 'length'), 10, 'should get new value'); + assert.equal(arr.length, 10, 'property should be accessible on arr'); + } - assert.equal(parent.b, 1, 'parent.b should be 1'); - assert.equal(child.b, 1, 'child.b should be 1'); - assert.equal(get(child, 'b'), 1, 'Ember.get(child, "b") should be 1'); + ['@test watch + ES5 getter'](assert) { + let parent = { b: 1 }; + let child = { + get b() { + return parent.b; + } + }; - watch(child, 'b'); + assert.equal(parent.b, 1, 'parent.b should be 1'); + assert.equal(child.b, 1, 'child.b should be 1'); + assert.equal(get(child, 'b'), 1, 'Ember.get(child, "b") should be 1'); - assert.equal(parent.b, 1, 'parent.b should be 1 (after watch)'); - assert.equal(child.b, 1, 'child.b should be 1 (after watch)'); + watch(child, 'b'); - assert.equal(get(child, 'b'), 1, 'Ember.get(child, "b") should be 1 (after watch)'); -}); + assert.equal(parent.b, 1, 'parent.b should be 1 (after watch)'); + assert.equal(child.b, 1, 'child.b should be 1 (after watch)'); + + assert.equal(get(child, 'b'), 1, 'Ember.get(child, "b") should be 1 (after watch)'); + } -testBoth('watch + Ember.set + no-descriptor', function(get, set, assert) { - let child = { }; + ['@test watch + Ember.set + no-descriptor'](assert) { + let child = { }; - assert.equal(child.b, undefined, 'child.b '); - assert.equal(get(child, 'b'), undefined, 'Ember.get(child, "b")'); + assert.equal(child.b, undefined, 'child.b '); + assert.equal(get(child, 'b'), undefined, 'Ember.get(child, "b")'); - watch(child, 'b'); - set(child, 'b', 1); + watch(child, 'b'); + set(child, 'b', 1); - assert.equal(child.b, 1, 'child.b (after watch)'); - assert.equal(get(child, 'b'), 1, 'Ember.get(child, "b") (after watch)'); + assert.equal(child.b, 1, 'child.b (after watch)'); + assert.equal(get(child, 'b'), 1, 'Ember.get(child, "b") (after watch)'); + } }); +