From b2f6c8112b8a3a17e722983fd68817546525f545 Mon Sep 17 00:00:00 2001 From: Travis Hoover Date: Sat, 30 Dec 2017 03:02:30 -0800 Subject: [PATCH] [CLEANUP] Convert ember-metal accessors tests to new style --- .../tests/accessors/get_path_test.js | 83 +-- .../tests/accessors/get_properties_test.js | 32 +- .../ember-metal/tests/accessors/get_test.js | 324 +++++----- .../tests/accessors/is_global_path_test.js | 26 +- .../tests/accessors/mandatory_setters_test.js | 606 +++++++++--------- .../tests/accessors/set_path_test.js | 90 +-- .../ember-metal/tests/accessors/set_test.js | 126 ++-- 7 files changed, 671 insertions(+), 616 deletions(-) diff --git a/packages/ember-metal/tests/accessors/get_path_test.js b/packages/ember-metal/tests/accessors/get_path_test.js index a1f5d7aa00b..50b4502c2a6 100644 --- a/packages/ember-metal/tests/accessors/get_path_test.js +++ b/packages/ember-metal/tests/accessors/get_path_test.js @@ -1,8 +1,11 @@ import { get } from '../..'; +import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; let obj; -const moduleOpts = { - setup() { + +moduleFor('Ember.get with path', class extends AbstractTestCase { + constructor() { + super(); obj = { foo: { bar: { @@ -21,59 +24,57 @@ const moduleOpts = { }, nullValue: null }; - }, + } teardown() { obj = undefined; } -}; - -QUnit.module('Ember.get with path', moduleOpts); -// .......................................................... -// LOCAL PATHS -// + // .......................................................... + // LOCAL PATHS + // + ['@test [obj, foo] -> obj.foo'](assert) { + assert.deepEqual(get(obj, 'foo'), obj.foo); + } -QUnit.test('[obj, foo] -> obj.foo', function() { - deepEqual(get(obj, 'foo'), obj.foo); -}); + ['@test [obj, foo.bar] -> obj.foo.bar'](assert) { + assert.deepEqual(get(obj, 'foo.bar'), obj.foo.bar); + } -QUnit.test('[obj, foo.bar] -> obj.foo.bar', function() { - deepEqual(get(obj, 'foo.bar'), obj.foo.bar); -}); + ['@test [obj, foothis.bar] -> obj.foothis.bar'](assert) { + assert.deepEqual(get(obj, 'foothis.bar'), obj.foothis.bar); + } -QUnit.test('[obj, foothis.bar] -> obj.foothis.bar', function() { - deepEqual(get(obj, 'foothis.bar'), obj.foothis.bar); -}); + ['@test [obj, falseValue.notDefined] -> (undefined)'](assert) { + assert.strictEqual(get(obj, 'falseValue.notDefined'), undefined); + } -QUnit.test('[obj, falseValue.notDefined] -> (undefined)', function() { - strictEqual(get(obj, 'falseValue.notDefined'), undefined); -}); + ['@test [obj, emptyString.length] -> 0'](assert) { + assert.strictEqual(get(obj, 'emptyString.length'), 0); + } -QUnit.test('[obj, emptyString.length] -> 0', function() { - strictEqual(get(obj, 'emptyString.length'), 0); -}); + ['@test [obj, nullValue.notDefined] -> (undefined)'](assert) { + assert.strictEqual(get(obj, 'nullValue.notDefined'), undefined); + } -QUnit.test('[obj, nullValue.notDefined] -> (undefined)', function() { - strictEqual(get(obj, 'nullValue.notDefined'), undefined); -}); + // .......................................................... + // GLOBAL PATHS TREATED LOCAL WITH GET + // -// .......................................................... -// GLOBAL PATHS TREATED LOCAL WITH GET -// + ['@test [obj, Wuz] -> obj.Wuz'](assert) { + assert.deepEqual(get(obj, 'Wuz'), obj.Wuz); + } -QUnit.test('[obj, Wuz] -> obj.Wuz', function() { - deepEqual(get(obj, 'Wuz'), obj.Wuz); -}); + ['@test [obj, Wuz.nar] -> obj.Wuz.nar'](assert) { + assert.deepEqual(get(obj, 'Wuz.nar'), obj.Wuz.nar); + } -QUnit.test('[obj, Wuz.nar] -> obj.Wuz.nar', function() { - deepEqual(get(obj, 'Wuz.nar'), obj.Wuz.nar); -}); + ['@test [obj, Foo] -> (undefined)'](assert) { + assert.strictEqual(get(obj, 'Foo'), undefined); + } -QUnit.test('[obj, Foo] -> (undefined)', function() { - strictEqual(get(obj, 'Foo'), undefined); + ['@test [obj, Foo.bar] -> (undefined)'](assert) { + assert.strictEqual(get(obj, 'Foo.bar'), undefined); + } }); -QUnit.test('[obj, Foo.bar] -> (undefined)', function() { - strictEqual(get(obj, 'Foo.bar'), undefined); -}); diff --git a/packages/ember-metal/tests/accessors/get_properties_test.js b/packages/ember-metal/tests/accessors/get_properties_test.js index ad3418fe97d..0be37f3d6c8 100644 --- a/packages/ember-metal/tests/accessors/get_properties_test.js +++ b/packages/ember-metal/tests/accessors/get_properties_test.js @@ -1,19 +1,21 @@ import { getProperties } from '../..'; +import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; -QUnit.module('Ember.getProperties'); +moduleFor('Ember.getProperties', class extends AbstractTestCase { + ['@test can retrieve a hash of properties from an object via an argument list or array of property names'](assert) { + let obj = { + firstName: 'Steve', + lastName: 'Jobs', + companyName: 'Apple, Inc.' + }; -QUnit.test('can retrieve a hash of properties from an object via an argument list or array of property names', function() { - let obj = { - firstName: 'Steve', - lastName: 'Jobs', - companyName: 'Apple, Inc.' - }; - - deepEqual(getProperties(obj, 'firstName', 'lastName'), { firstName: 'Steve', lastName: 'Jobs' }); - deepEqual(getProperties(obj, 'firstName', 'lastName'), { firstName: 'Steve', lastName: 'Jobs' }); - deepEqual(getProperties(obj, 'lastName'), { lastName: 'Jobs' }); - deepEqual(getProperties(obj), {}); - deepEqual(getProperties(obj, ['firstName', 'lastName']), { firstName: 'Steve', lastName: 'Jobs' }); - deepEqual(getProperties(obj, ['firstName']), { firstName: 'Steve' }); - deepEqual(getProperties(obj, []), {}); + assert.deepEqual(getProperties(obj, 'firstName', 'lastName'), { firstName: 'Steve', lastName: 'Jobs' }); + assert.deepEqual(getProperties(obj, 'firstName', 'lastName'), { firstName: 'Steve', lastName: 'Jobs' }); + assert.deepEqual(getProperties(obj, 'lastName'), { lastName: 'Jobs' }); + assert.deepEqual(getProperties(obj), {}); + assert.deepEqual(getProperties(obj, ['firstName', 'lastName']), { firstName: 'Steve', lastName: 'Jobs' }); + assert.deepEqual(getProperties(obj, ['firstName']), { firstName: 'Steve' }); + assert.deepEqual(getProperties(obj, []), {}); + } }); + diff --git a/packages/ember-metal/tests/accessors/get_test.js b/packages/ember-metal/tests/accessors/get_test.js index 62c5ea64481..e2e8b5596ed 100644 --- a/packages/ember-metal/tests/accessors/get_test.js +++ b/packages/ember-metal/tests/accessors/get_test.js @@ -1,184 +1,220 @@ -import { testBoth } from 'internal-test-helpers'; +import { ENV } from 'ember-environment'; import { get, getWithDefault, Mixin, - observer + observer, } from '../..'; - -QUnit.module('Ember.get'); - -QUnit.test('should get arbitrary properties on an object', function() { - let obj = { - string: 'string', - number: 23, - boolTrue: true, - boolFalse: false, - nullValue: null - }; - - for (let key in obj) { - if (!obj.hasOwnProperty(key)) { - continue; +import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; + +function aget(x, y) { return x[y]; } + +moduleFor('Ember.get', class extends AbstractTestCase { + ['@test should get arbitrary properties on an object'](assert) { + let obj = { + string: 'string', + number: 23, + boolTrue: true, + boolFalse: false, + nullValue: null + }; + + for (let key in obj) { + if (!obj.hasOwnProperty(key)) { + continue; + } + assert.equal(get(obj, key), obj[key], key); } - equal(get(obj, key), obj[key], key); } -}); -QUnit.test('should not access a property more than once', function() { - let count = 0; - let obj = { - get id() { return ++count; } - }; + ['@test should not access a property more than once'](assert) { + let count = 0; + let obj = { + get id() { return ++count; } + }; - get(obj, 'id'); + get(obj, 'id'); - equal(count, 1); -}); + assert.equal(count, 1); + } -testBoth('should call unknownProperty on watched values if the value is undefined', function(get) { - let obj = { - unknownProperty(key) { - equal(key, 'foo', 'should pass key'); - return 'FOO'; + ['@test should call unknownProperty on watched values if the value is undefined using getFromEmberMetal()/Ember.set()'](assert) { + let obj = { + unknownProperty(key) { + assert.equal(key, 'foo', 'should pass key'); + return 'FOO'; + } + }; + assert.equal(get(obj, 'foo'), 'FOO', 'should return value from unknown'); + } + + ['@test should call unknownProperty on watched values if the value is undefined using accessors'](assert) { + if (ENV.USES_ACCESSORS) { + let obj = { + unknownProperty(key) { + assert.equal(key, 'foo', 'should pass key'); + return 'FOO'; + } + }; + assert.equal(aget(obj, 'foo'), 'FOO', 'should return value from unknown'); + } else { + assert.ok('SKIPPING ACCESSORS'); } - }; - equal(get(obj, 'foo'), 'FOO', 'should return value from unknown'); -}); + } -QUnit.test('warn on attempts to call get with no arguments', function() { - expectAssertion(function() { - get('aProperty'); - }, /Get must be called with two arguments;/i); -}); + ['@test warn on attempts to call get with no arguments']() { + expectAssertion(function() { + get('aProperty'); + }, /Get must be called with two arguments;/i); + } -QUnit.test('warn on attempts to call get with only one argument', function() { - expectAssertion(function() { - get('aProperty'); - }, /Get must be called with two arguments;/i); -}); + ['@test warn on attempts to call get with only one argument']() { + expectAssertion(function() { + get('aProperty'); + }, /Get must be called with two arguments;/i); + } -QUnit.test('warn on attempts to call get with more then two arguments', function() { - expectAssertion(function() { - get({}, 'aProperty', true); - }, /Get must be called with two arguments;/i); -}); + ['@test warn on attempts to call get with more then two arguments']() { + expectAssertion(function() { + get({}, 'aProperty', true); + }, /Get must be called with two arguments;/i); + } -QUnit.test('warn on attempts to get a property of undefined', function() { - expectAssertion(function() { - get(undefined, 'aProperty'); - }, /Cannot call get with 'aProperty' on an undefined object/i); -}); + ['@test warn on attempts to get a property of undefined']() { + expectAssertion(function() { + get(undefined, 'aProperty'); + }, /Cannot call get with 'aProperty' on an undefined object/i); + } -QUnit.test('warn on attempts to get a property path of undefined', function() { - expectAssertion(function() { - get(undefined, 'aProperty.on.aPath'); - }, /Cannot call get with 'aProperty.on.aPath' on an undefined object/); -}); + ['@test warn on attempts to get a property path of undefined']() { + expectAssertion(function() { + get(undefined, 'aProperty.on.aPath'); + }, /Cannot call get with 'aProperty.on.aPath' on an undefined object/); + } -QUnit.test('warn on attempts to get a property of null', function() { - expectAssertion(function() { - get(null, 'aProperty'); - }, /Cannot call get with 'aProperty' on an undefined object/); -}); + ['@test warn on attempts to get a property of null']() { + expectAssertion(function() { + get(null, 'aProperty'); + }, /Cannot call get with 'aProperty' on an undefined object/); + } -QUnit.test('warn on attempts to get a property path of null', function() { - expectAssertion(function() { - get(null, 'aProperty.on.aPath'); - }, /Cannot call get with 'aProperty.on.aPath' on an undefined object/); -}); + ['@test warn on attempts to get a property path of null']() { + expectAssertion(function() { + get(null, 'aProperty.on.aPath'); + }, /Cannot call get with 'aProperty.on.aPath' on an undefined object/); + } -QUnit.test('warn on attempts to use get with an unsupported property path', function() { - let obj = {}; - expectAssertion(() => get(obj, null), /The key provided to get must be a string, you passed null/); - expectAssertion(() => get(obj, NaN), /The key provided to get must be a string, you passed NaN/); - expectAssertion(() => get(obj, undefined), /The key provided to get must be a string, you passed undefined/); - expectAssertion(() => get(obj, false), /The key provided to get must be a string, you passed false/); - expectAssertion(() => get(obj, 42), /The key provided to get must be a string, you passed 42/); - expectAssertion(() => get(obj, ''), /Cannot call `Ember.get` with an empty string/); -}); + ['@test warn on attempts to use get with an unsupported property path']() { + let obj = {}; + expectAssertion(() => get(obj, null), /The key provided to get must be a string, you passed null/); + expectAssertion(() => get(obj, NaN), /The key provided to get must be a string, you passed NaN/); + expectAssertion(() => get(obj, undefined), /The key provided to get must be a string, you passed undefined/); + expectAssertion(() => get(obj, false), /The key provided to get must be a string, you passed false/); + expectAssertion(() => get(obj, 42), /The key provided to get must be a string, you passed 42/); + expectAssertion(() => get(obj, ''), /Cannot call `Ember.get` with an empty string/); + } -// .......................................................... -// BUGS -// + // .......................................................... + // BUGS + // -QUnit.test('(regression) watched properties on unmodified inherited objects should still return their original value', function() { - let MyMixin = Mixin.create({ - someProperty: 'foo', - propertyDidChange: observer('someProperty', () => {}) - }); + ['@test (regression) watched properties on unmodified inherited objects should still return their original value']() { + let MyMixin = Mixin.create({ + someProperty: 'foo', + propertyDidChange: observer('someProperty', () => {}) + }); - let baseObject = MyMixin.apply({}); - let theRealObject = Object.create(baseObject); + let baseObject = MyMixin.apply({}); + let theRealObject = Object.create(baseObject); - equal(get(theRealObject, 'someProperty'), 'foo', 'should return the set value, not false'); + equal(get(theRealObject, 'someProperty'), 'foo', 'should return the set value, not false'); + } }); -QUnit.module('Ember.getWithDefault'); - -QUnit.test('should get arbitrary properties on an object', function() { - let obj = { - string: 'string', - number: 23, - boolTrue: true, - boolFalse: false, - nullValue: null - }; +moduleFor('Ember.getWithDefault', class extends AbstractTestCase { + ['@test should get arbitrary properties on an object'](assert) { + let obj = { + string: 'string', + number: 23, + boolTrue: true, + boolFalse: false, + nullValue: null + }; - for (let key in obj) { - if (!obj.hasOwnProperty(key)) { - continue; + for (let key in obj) { + if (!obj.hasOwnProperty(key)) { + continue; + } + assert.equal(getWithDefault(obj, key, 'fail'), obj[key], key); } - equal(getWithDefault(obj, key, 'fail'), obj[key], key); - } - - obj = { - undef: undefined - }; - equal(getWithDefault(obj, 'undef', 'default'), 'default', 'explicit undefined retrieves the default'); - equal(getWithDefault(obj, 'not-present', 'default'), 'default', 'non-present key retrieves the default'); -}); - -QUnit.test('should call unknownProperty if defined and value is undefined', function() { - let obj = { - count: 0, - unknownProperty(key) { - equal(key, 'foo', 'should pass key'); - this.count++; - return 'FOO'; - } - }; + obj = { + undef: undefined + }; - equal(get(obj, 'foo'), 'FOO', 'should return value from unknown'); - equal(obj.count, 1, 'should have invoked'); -}); + assert.equal(getWithDefault(obj, 'undef', 'default'), 'default', 'explicit undefined retrieves the default'); + assert.equal(getWithDefault(obj, 'not-present', 'default'), 'default', 'non-present key retrieves the default'); + } -testBoth('if unknownProperty is present, it is called', function() { - let obj = { - unknownProperty(key) { - if (key === 'foo') { + ['@test should call unknownProperty if defined and value is undefined'](assert) { + let obj = { + count: 0, + unknownProperty(key) { equal(key, 'foo', 'should pass key'); + this.count++; return 'FOO'; } + }; + + assert.equal(get(obj, 'foo'), 'FOO', 'should return value from unknown'); + assert.equal(obj.count, 1, 'should have invoked'); + } + + ['@test if unknownProperty is present, it is called using getFromEmberMetal()/Ember.set()'](assert) { + let obj = { + unknownProperty(key) { + if (key === 'foo') { + equal(key, 'foo', 'should pass key'); + return 'FOO'; + } + } + }; + assert.equal(getWithDefault(obj, 'foo', 'fail'), 'FOO', 'should return value from unknownProperty'); + assert.equal(getWithDefault(obj, 'bar', 'default'), 'default', 'should convert undefined from unknownProperty into default'); + } + + ['@test if unknownProperty is present, it is called using accessors'](assert) { + if (ENV.USES_ACCESSORS) { + let obj = { + unknownProperty(key) { + if (key === 'foo') { + assert.equal(key, 'foo', 'should pass key'); + return 'FOO'; + } + } + }; + assert.equal(aget(obj, 'foo', 'fail'), 'FOO', 'should return value from unknownProperty'); + assert.equal(aget(obj, 'bar', 'default'), 'default', 'should convert undefined from unknownProperty into default'); + + } else { + assert.ok('SKIPPING ACCESSORS'); } - }; - equal(getWithDefault(obj, 'foo', 'fail'), 'FOO', 'should return value from unknownProperty'); - equal(getWithDefault(obj, 'bar', 'default'), 'default', 'should convert undefined from unknownProperty into default'); -}); + } -// .......................................................... -// BUGS -// + // .......................................................... + // BUGS + // -QUnit.test('(regression) watched properties on unmodified inherited objects should still return their original value', function() { - let MyMixin = Mixin.create({ - someProperty: 'foo', - propertyDidChange: observer('someProperty', () => { /* nothing to do */}) - }); + ['@test (regression) watched properties on unmodified inherited objects should still return their original value'](assert) { + let MyMixin = Mixin.create({ + someProperty: 'foo', + propertyDidChange: observer('someProperty', () => { /* nothing to do */}) + }); - let baseObject = MyMixin.apply({}); - let theRealObject = Object.create(baseObject); + let baseObject = MyMixin.apply({}); + let theRealObject = Object.create(baseObject); - equal(getWithDefault(theRealObject, 'someProperty', 'fail'), 'foo', 'should return the set value, not false'); + assert.equal(getWithDefault(theRealObject, 'someProperty', 'fail'), 'foo', 'should return the set value, not false'); + } }); + diff --git a/packages/ember-metal/tests/accessors/is_global_path_test.js b/packages/ember-metal/tests/accessors/is_global_path_test.js index a3806a8a0b6..08e12f2603c 100644 --- a/packages/ember-metal/tests/accessors/is_global_path_test.js +++ b/packages/ember-metal/tests/accessors/is_global_path_test.js @@ -1,18 +1,20 @@ import { isGlobalPath } from '../..'; +import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; -QUnit.module('Ember.isGlobalPath'); +moduleFor('Ember.isGlobalPath', class extends AbstractTestCase { + ['@test global path\'s are recognized'](assert) { + assert.ok(isGlobalPath('App.myProperty')); + assert.ok(isGlobalPath('App.myProperty.subProperty')); + } -QUnit.test('global path\'s are recognized', function() { - ok(isGlobalPath('App.myProperty')); - ok(isGlobalPath('App.myProperty.subProperty')); -}); + ['@test if there is a \'this\' in the path, it\'s not a global path'](assert) { + assert.ok(!isGlobalPath('this.myProperty')); + assert.ok(!isGlobalPath('this')); + } -QUnit.test('if there is a \'this\' in the path, it\'s not a global path', function() { - ok(!isGlobalPath('this.myProperty')); - ok(!isGlobalPath('this')); + ['@test if the path starts with a lowercase character, it is not a global path'](assert) { + assert.ok(!isGlobalPath('myObj')); + assert.ok(!isGlobalPath('myObj.SecondProperty')); + } }); -QUnit.test('if the path starts with a lowercase character, it is not a global path', function() { - ok(!isGlobalPath('myObj')); - ok(!isGlobalPath('myObj.SecondProperty')); -}); diff --git a/packages/ember-metal/tests/accessors/mandatory_setters_test.js b/packages/ember-metal/tests/accessors/mandatory_setters_test.js index 7eb30cade50..fe80a8395d9 100644 --- a/packages/ember-metal/tests/accessors/mandatory_setters_test.js +++ b/packages/ember-metal/tests/accessors/mandatory_setters_test.js @@ -6,8 +6,7 @@ import { unwatch, meta as metaFor } from '../..'; - -QUnit.module('mandatory-setters'); +import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; function hasMandatorySetter(object, property) { try { @@ -22,416 +21,417 @@ function hasMetaValue(object, property) { } if (MANDATORY_SETTER) { - QUnit.test('does not assert if property is not being watched', function() { - let obj = { - someProp: null, - toString() { - return 'custom-object'; - } - }; - - obj.someProp = 'blastix'; - equal(get(obj, 'someProp'), 'blastix'); - }); - - QUnit.test('should not setup mandatory-setter if property is not writable', function() { - expect(6); - - let obj = { }; - - Object.defineProperty(obj, 'a', { value: true }); - Object.defineProperty(obj, 'b', { value: false }); - Object.defineProperty(obj, 'c', { value: undefined }); - Object.defineProperty(obj, 'd', { value: undefined, writable: false }); - Object.defineProperty(obj, 'e', { value: undefined, configurable: false }); - Object.defineProperty(obj, 'f', { value: undefined, configurable: true }); - - watch(obj, 'a'); - watch(obj, 'b'); - watch(obj, 'c'); - watch(obj, 'd'); - watch(obj, 'e'); - watch(obj, 'f'); - - ok(!hasMandatorySetter(obj, 'a'), 'mandatory-setter should not be installed'); - ok(!hasMandatorySetter(obj, 'b'), 'mandatory-setter should not be installed'); - ok(!hasMandatorySetter(obj, 'c'), 'mandatory-setter should not be installed'); - ok(!hasMandatorySetter(obj, 'd'), 'mandatory-setter should not be installed'); - ok(!hasMandatorySetter(obj, 'e'), 'mandatory-setter should not be installed'); - ok(!hasMandatorySetter(obj, 'f'), 'mandatory-setter should not be installed'); - }); + moduleFor('mandory-setters', class extends AbstractTestCase { + ['@test does not assert if property is not being watched'](assert) { + let obj = { + someProp: null, + toString() { + return 'custom-object'; + } + }; + + obj.someProp = 'blastix'; + assert.equal(get(obj, 'someProp'), 'blastix'); + } - QUnit.test('should not teardown non mandatory-setter descriptor', function() { - expect(1); + ['@test should not setup mandatory-setter if property is not writable'](assert) { + expect(6); + + let obj = { }; + + Object.defineProperty(obj, 'a', { value: true }); + Object.defineProperty(obj, 'b', { value: false }); + Object.defineProperty(obj, 'c', { value: undefined }); + Object.defineProperty(obj, 'd', { value: undefined, writable: false }); + Object.defineProperty(obj, 'e', { value: undefined, configurable: false }); + Object.defineProperty(obj, 'f', { value: undefined, configurable: true }); + + watch(obj, 'a'); + watch(obj, 'b'); + watch(obj, 'c'); + watch(obj, 'd'); + watch(obj, 'e'); + watch(obj, 'f'); + + assert.ok(!hasMandatorySetter(obj, 'a'), 'mandatory-setter should not be installed'); + assert.ok(!hasMandatorySetter(obj, 'b'), 'mandatory-setter should not be installed'); + assert.ok(!hasMandatorySetter(obj, 'c'), 'mandatory-setter should not be installed'); + assert.ok(!hasMandatorySetter(obj, 'd'), 'mandatory-setter should not be installed'); + assert.ok(!hasMandatorySetter(obj, 'e'), 'mandatory-setter should not be installed'); + assert.ok(!hasMandatorySetter(obj, 'f'), 'mandatory-setter should not be installed'); + } - let obj = { get a() { return 'hi'; } }; + ['@test should not teardown non mandatory-setter descriptor'](assert) { + expect(1); - watch(obj, 'a'); - unwatch(obj, 'a'); + let obj = { get a() { return 'hi'; } }; - equal(obj.a, 'hi'); - }); + watch(obj, 'a'); + unwatch(obj, 'a'); - QUnit.test('should not confuse non descriptor watched gets', function() { - expect(2); + assert.equal(obj.a, 'hi'); + } - let obj = { get a() { return 'hi'; } }; + ['@test should not confuse non descriptor watched gets'](assert) { + expect(2); - watch(obj, 'a'); - equal(get(obj, 'a'), 'hi'); - equal(obj.a, 'hi'); - }); + let obj = { get a() { return 'hi'; } }; - QUnit.test('should not setup mandatory-setter if setter is already setup on property', function() { - expect(2); + watch(obj, 'a'); + assert.equal(get(obj, 'a'), 'hi'); + assert.equal(obj.a, 'hi'); + } - let obj = { someProp: null }; + ['@test should not setup mandatory-setter if setter is already setup on property'](assert) { + expect(2); - Object.defineProperty(obj, 'someProp', { - get() { - return null; - }, + let obj = { someProp: null }; - set(value) { - equal(value, 'foo-bar', 'custom setter was called'); - } - }); + Object.defineProperty(obj, 'someProp', { + get() { + return null; + }, - watch(obj, 'someProp'); - ok(!hasMandatorySetter(obj, 'someProp'), 'mandatory-setter should not be installed'); + set(value) { + assert.equal(value, 'foo-bar', 'custom setter was called'); + } + }); - obj.someProp = 'foo-bar'; - }); + watch(obj, 'someProp'); + assert.ok(!hasMandatorySetter(obj, 'someProp'), 'mandatory-setter should not be installed'); - QUnit.test('watched ES5 setter should not be smashed by mandatory setter', function() { - let value; - let obj = { - get foo() { }, - set foo(_value) { - value = _value; - } - }; + obj.someProp = 'foo-bar'; + } - watch(obj, 'foo'); + ['@test watched ES5 setter should not be smashed by mandatory setter'](assert) { + let value; + let obj = { + get foo() { }, + set foo(_value) { + value = _value; + } + }; - set(obj, 'foo', 2); - equal(value, 2); - }); + watch(obj, 'foo'); - QUnit.test('should not setup mandatory-setter if setter is already setup on property in parent prototype', function() { - expect(2); + set(obj, 'foo', 2); + assert.equal(value, 2); + } - function Foo() { } + ['@test should not setup mandatory-setter if setter is already setup on property in parent prototype'](assert) { + expect(2); - Object.defineProperty(Foo.prototype, 'someProp', { - get() { - return null; - }, + function Foo() { } - set(value) { - equal(value, 'foo-bar', 'custom setter was called'); - } - }); + Object.defineProperty(Foo.prototype, 'someProp', { + get() { + return null; + }, - let obj = new Foo(); + set(value) { + assert.equal(value, 'foo-bar', 'custom setter was called'); + } + }); - watch(obj, 'someProp'); - ok(!hasMandatorySetter(obj, 'someProp'), 'mandatory-setter should not be installed'); + let obj = new Foo(); - obj.someProp = 'foo-bar'; - }); + watch(obj, 'someProp'); + assert.ok(!hasMandatorySetter(obj, 'someProp'), 'mandatory-setter should not be installed'); - QUnit.test('should not setup mandatory-setter if setter is already setup on property in grandparent prototype', function() { - expect(2); - - function Foo() { } - - Object.defineProperty(Foo.prototype, 'someProp', { - get() { - return null; - }, + obj.someProp = 'foo-bar'; + } - set(value) { - equal(value, 'foo-bar', 'custom setter was called'); - } - }); + ['@test should not setup mandatory-setter if setter is already setup on property in grandparent prototype'](assert) { + expect(2); - function Bar() { } - Bar.prototype = Object.create(Foo.prototype); - Bar.prototype.constructor = Bar; + function Foo() { } - let obj = new Bar(); + Object.defineProperty(Foo.prototype, 'someProp', { + get() { + return null; + }, - watch(obj, 'someProp'); - ok(!hasMandatorySetter(obj, 'someProp'), 'mandatory-setter should not be installed'); + set(value) { + assert.equal(value, 'foo-bar', 'custom setter was called'); + } + }); - obj.someProp = 'foo-bar'; - }); + function Bar() { } + Bar.prototype = Object.create(Foo.prototype); + Bar.prototype.constructor = Bar; - QUnit.test('should not setup mandatory-setter if setter is already setup on property in great grandparent prototype', function() { - expect(2); + let obj = new Bar(); - function Foo() { } + watch(obj, 'someProp'); + assert.ok(!hasMandatorySetter(obj, 'someProp'), 'mandatory-setter should not be installed'); - Object.defineProperty(Foo.prototype, 'someProp', { - get() { - return null; - }, + obj.someProp = 'foo-bar'; + } - set(value) { - equal(value, 'foo-bar', 'custom setter was called'); - } - }); + ['@test should not setup mandatory-setter if setter is already setup on property in great grandparent prototype'](assert) { + expect(2); - function Bar() { } - Bar.prototype = Object.create(Foo.prototype); - Bar.prototype.constructor = Bar; + function Foo() { } - function Qux() { } - Qux.prototype = Object.create(Bar.prototype); - Qux.prototype.constructor = Qux; + Object.defineProperty(Foo.prototype, 'someProp', { + get() { + return null; + }, - let obj = new Qux(); + set(value) { + assert.equal(value, 'foo-bar', 'custom setter was called'); + } + }); - watch(obj, 'someProp'); - ok(!hasMandatorySetter(obj, 'someProp'), 'mandatory-setter should not be installed'); + function Bar() { } + Bar.prototype = Object.create(Foo.prototype); + Bar.prototype.constructor = Bar; - obj.someProp = 'foo-bar'; - }); + function Qux() { } + Qux.prototype = Object.create(Bar.prototype); + Qux.prototype.constructor = Qux; - QUnit.test('should assert if set without set when property is being watched', function() { - let obj = { - someProp: null, - toString() { - return 'custom-object'; - } - }; + let obj = new Qux(); - watch(obj, 'someProp'); + watch(obj, 'someProp'); + assert.ok(!hasMandatorySetter(obj, 'someProp'), 'mandatory-setter should not be installed'); - expectAssertion(function() { obj.someProp = 'foo-bar'; - }, 'You must use set() to set the `someProp` property (of custom-object) to `foo-bar`.'); - }); - - QUnit.test('should not assert if set with set when property is being watched', function() { - let obj = { - someProp: null, - toString() { - return 'custom-object'; - } - }; + } - watch(obj, 'someProp'); - set(obj, 'someProp', 'foo-bar'); + ['@test should assert if set without set when property is being watched']() { + let obj = { + someProp: null, + toString() { + return 'custom-object'; + } + }; - equal(get(obj, 'someProp'), 'foo-bar'); - }); + watch(obj, 'someProp'); - QUnit.test('does not setup mandatory-setter if non-configurable', function() { - let obj = { - someProp: null, - toString() { - return 'custom-object'; - } - }; + expectAssertion(function() { + obj.someProp = 'foo-bar'; + }, 'You must use set() to set the `someProp` property (of custom-object) to `foo-bar`.'); + } - Object.defineProperty(obj, 'someProp', { - configurable: false, - enumerable: true, - value: 'blastix' - }); + ['@test should not assert if set with set when property is being watched'](assert) { + let obj = { + someProp: null, + toString() { + return 'custom-object'; + } + }; - watch(obj, 'someProp'); - ok(!(hasMandatorySetter(obj, 'someProp')), 'blastix'); - }); + watch(obj, 'someProp'); + set(obj, 'someProp', 'foo-bar'); - QUnit.test('ensure after watch the property is restored (and the value is no-longer stored in meta) [non-enumerable]', function() { - let obj = { - someProp: null, - toString() { - return 'custom-object'; - } - }; + assert.equal(get(obj, 'someProp'), 'foo-bar'); + } - Object.defineProperty(obj, 'someProp', { - configurable: true, - enumerable: false, - value: 'blastix' - }); + ['@test does not setup mandatory-setter if non-configurable'](assert) { + let obj = { + someProp: null, + toString() { + return 'custom-object'; + } + }; + + Object.defineProperty(obj, 'someProp', { + configurable: false, + enumerable: true, + value: 'blastix' + }); + + watch(obj, 'someProp'); + assert.ok(!(hasMandatorySetter(obj, 'someProp')), 'blastix'); + } - watch(obj, 'someProp'); - equal(hasMandatorySetter(obj, 'someProp'), true, 'should have a mandatory setter'); + ['@test ensure after watch the property is restored (and the value is no-longer stored in meta) [non-enumerable]'](assert) { + let obj = { + someProp: null, + toString() { + return 'custom-object'; + } + }; - let descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp'); + Object.defineProperty(obj, 'someProp', { + configurable: true, + enumerable: false, + value: 'blastix' + }); - equal(descriptor.enumerable, false, 'property should remain non-enumerable'); - equal(descriptor.configurable, true, 'property should remain configurable'); - equal(obj.someProp, 'blastix', 'expected value to be the getter'); + watch(obj, 'someProp'); + assert.equal(hasMandatorySetter(obj, 'someProp'), true, 'should have a mandatory setter'); - equal(descriptor.value, undefined, 'expected existing value to NOT remain'); + let descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp'); - ok(hasMetaValue(obj, 'someProp'), 'someProp is stored in meta.values'); + assert.equal(descriptor.enumerable, false, 'property should remain non-enumerable'); + assert.equal(descriptor.configurable, true, 'property should remain configurable'); + assert.equal(obj.someProp, 'blastix', 'expected value to be the getter'); - unwatch(obj, 'someProp'); + assert.equal(descriptor.value, undefined, 'expected existing value to NOT remain'); - ok(!hasMetaValue(obj, 'someProp'), 'someProp is no longer stored in meta.values'); + assert.ok(hasMetaValue(obj, 'someProp'), 'someProp is stored in meta.values'); - descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp'); + unwatch(obj, 'someProp'); - equal(hasMandatorySetter(obj, 'someProp'), false, 'should no longer have a mandatory setter'); + assert.ok(!hasMetaValue(obj, 'someProp'), 'someProp is no longer stored in meta.values'); - equal(descriptor.enumerable, false, 'property should remain non-enumerable'); - equal(descriptor.configurable, true, 'property should remain configurable'); - equal(obj.someProp, 'blastix', 'expected value to be the getter'); - equal(descriptor.value, 'blastix', 'expected existing value to remain'); + descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp'); - obj.someProp = 'new value'; + assert.equal(hasMandatorySetter(obj, 'someProp'), false, 'should no longer have a mandatory setter'); - // make sure the descriptor remains correct (nothing funky, like a redefined, happened in the setter); - descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp'); + assert.equal(descriptor.enumerable, false, 'property should remain non-enumerable'); + assert.equal(descriptor.configurable, true, 'property should remain configurable'); + assert.equal(obj.someProp, 'blastix', 'expected value to be the getter'); + assert.equal(descriptor.value, 'blastix', 'expected existing value to remain'); - equal(descriptor.enumerable, false, 'property should remain non-enumerable'); - equal(descriptor.configurable, true, 'property should remain configurable'); - equal(descriptor.value, 'new value', 'expected existing value to NOT remain'); - equal(obj.someProp, 'new value', 'expected value to be the getter'); - equal(obj.someProp, 'new value'); - }); + obj.someProp = 'new value'; - QUnit.test('ensure after watch the property is restored (and the value is no-longer stored in meta) [enumerable]', function() { - let obj = { - someProp: null, - toString() { - return 'custom-object'; - } - }; + // make sure the descriptor remains correct (nothing funky, like a redefined, happened in the setter); + descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp'); - Object.defineProperty(obj, 'someProp', { - configurable: true, - enumerable: true, - value: 'blastix' - }); + assert.equal(descriptor.enumerable, false, 'property should remain non-enumerable'); + assert.equal(descriptor.configurable, true, 'property should remain configurable'); + assert.equal(descriptor.value, 'new value', 'expected existing value to NOT remain'); + assert.equal(obj.someProp, 'new value', 'expected value to be the getter'); + assert.equal(obj.someProp, 'new value'); + } - watch(obj, 'someProp'); - equal(hasMandatorySetter(obj, 'someProp'), true, 'should have a mandatory setter'); + ['@test ensure after watch the property is restored (and the value is no-longer stored in meta) [enumerable]'](assert) { + let obj = { + someProp: null, + toString() { + return 'custom-object'; + } + }; - let descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp'); + Object.defineProperty(obj, 'someProp', { + configurable: true, + enumerable: true, + value: 'blastix' + }); - equal(descriptor.enumerable, true, 'property should remain enumerable'); - equal(descriptor.configurable, true, 'property should remain configurable'); - equal(obj.someProp, 'blastix', 'expected value to be the getter'); + watch(obj, 'someProp'); + assert.equal(hasMandatorySetter(obj, 'someProp'), true, 'should have a mandatory setter'); - equal(descriptor.value, undefined, 'expected existing value to NOT remain'); + let descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp'); - ok(hasMetaValue(obj, 'someProp'), 'someProp is stored in meta.values'); + assert.equal(descriptor.enumerable, true, 'property should remain enumerable'); + assert.equal(descriptor.configurable, true, 'property should remain configurable'); + assert.equal(obj.someProp, 'blastix', 'expected value to be the getter'); - unwatch(obj, 'someProp'); + assert.equal(descriptor.value, undefined, 'expected existing value to NOT remain'); - ok(!hasMetaValue(obj, 'someProp'), 'someProp is no longer stored in meta.values'); + assert.ok(hasMetaValue(obj, 'someProp'), 'someProp is stored in meta.values'); - descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp'); + unwatch(obj, 'someProp'); - equal(hasMandatorySetter(obj, 'someProp'), false, 'should no longer have a mandatory setter'); + assert.ok(!hasMetaValue(obj, 'someProp'), 'someProp is no longer stored in meta.values'); - equal(descriptor.enumerable, true, 'property should remain enumerable'); - equal(descriptor.configurable, true, 'property should remain configurable'); - equal(obj.someProp, 'blastix', 'expected value to be the getter'); - equal(descriptor.value, 'blastix', 'expected existing value to remain'); + descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp'); - obj.someProp = 'new value'; + assert.equal(hasMandatorySetter(obj, 'someProp'), false, 'should no longer have a mandatory setter'); - // make sure the descriptor remains correct (nothing funky, like a redefined, happened in the setter); - descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp'); + assert.equal(descriptor.enumerable, true, 'property should remain enumerable'); + assert.equal(descriptor.configurable, true, 'property should remain configurable'); + assert.equal(obj.someProp, 'blastix', 'expected value to be the getter'); + assert.equal(descriptor.value, 'blastix', 'expected existing value to remain'); - equal(descriptor.enumerable, true, 'property should remain enumerable'); - equal(descriptor.configurable, true, 'property should remain configurable'); - equal(descriptor.value, 'new value', 'expected existing value to NOT remain'); - equal(obj.someProp, 'new value'); - }); + obj.someProp = 'new value'; - QUnit.test('sets up mandatory-setter if property comes from prototype', function() { - expect(2); + // make sure the descriptor remains correct (nothing funky, like a redefined, happened in the setter); + descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp'); - let obj = { - someProp: null, - toString() { - return 'custom-object'; - } - }; + assert.equal(descriptor.enumerable, true, 'property should remain enumerable'); + assert.equal(descriptor.configurable, true, 'property should remain configurable'); + assert.equal(descriptor.value, 'new value', 'expected existing value to NOT remain'); + assert.equal(obj.someProp, 'new value'); + } - let obj2 = Object.create(obj); + ['@test sets up mandatory-setter if property comes from prototype'](assert) { + expect(2); - watch(obj2, 'someProp'); + let obj = { + someProp: null, + toString() { + return 'custom-object'; + } + }; - ok(hasMandatorySetter(obj2, 'someProp'), 'mandatory setter has been setup'); + let obj2 = Object.create(obj); - expectAssertion(function() { - obj2.someProp = 'foo-bar'; - }, 'You must use set() to set the `someProp` property (of custom-object) to `foo-bar`.'); - }); + watch(obj2, 'someProp'); - QUnit.test('inheritance remains live', function() { - function Parent() {} - Parent.prototype.food = 'chips'; + assert.ok(hasMandatorySetter(obj2, 'someProp'), 'mandatory setter has been setup'); - let child = new Parent(); + expectAssertion(function() { + obj2.someProp = 'foo-bar'; + }, 'You must use set() to set the `someProp` property (of custom-object) to `foo-bar`.'); + } - equal(child.food, 'chips'); + ['@test inheritance remains live'](assert) { + function Parent() {} + Parent.prototype.food = 'chips'; - watch(child, 'food'); + let child = new Parent(); - equal(child.food, 'chips'); + assert.equal(child.food, 'chips'); - Parent.prototype.food = 'icecreame'; + watch(child, 'food'); - equal(child.food, 'icecreame'); + assert.equal(child.food, 'chips'); - unwatch(child, 'food'); + Parent.prototype.food = 'icecreame'; - equal(child.food, 'icecreame'); + assert.equal(child.food, 'icecreame'); - Parent.prototype.food = 'chips'; + unwatch(child, 'food'); - equal(child.food, 'chips'); - }); + assert.equal(child.food, 'icecreame'); + Parent.prototype.food = 'chips'; - QUnit.test('inheritance remains live and preserves this', function() { - function Parent(food) { - this._food = food; + assert.equal(child.food, 'chips'); } - Object.defineProperty(Parent.prototype, 'food', { - get() { - return this._food; + ['@test inheritance remains live and preserves this'](assert) { + function Parent(food) { + this._food = food; } - }); - let child = new Parent('chips'); + Object.defineProperty(Parent.prototype, 'food', { + get() { + return this._food; + } + }); + + let child = new Parent('chips'); - equal(child.food, 'chips'); + assert.equal(child.food, 'chips'); - watch(child, 'food'); + watch(child, 'food'); - equal(child.food, 'chips'); + assert.equal(child.food, 'chips'); - child._food = 'icecreame'; + child._food = 'icecreame'; - equal(child.food, 'icecreame'); + assert.equal(child.food, 'icecreame'); - unwatch(child, 'food'); + unwatch(child, 'food'); - equal(child.food, 'icecreame'); + assert.equal(child.food, 'icecreame'); - let foodDesc = Object.getOwnPropertyDescriptor(Parent.prototype, 'food'); - ok(!foodDesc.configurable, 'Parent.prototype.food desc should be non configable'); - ok(!foodDesc.enumerable, 'Parent.prototype.food desc should be non enumerable'); + let foodDesc = Object.getOwnPropertyDescriptor(Parent.prototype, 'food'); + assert.ok(!foodDesc.configurable, 'Parent.prototype.food desc should be non configable'); + assert.ok(!foodDesc.enumerable, 'Parent.prototype.food desc should be non enumerable'); - equal(foodDesc.get.call({ - _food: 'hi' - }), 'hi'); - equal(foodDesc.set, undefined); + assert.equal(foodDesc.get.call({ + _food: 'hi' + }), 'hi'); + assert.equal(foodDesc.set, undefined); - equal(child.food, 'icecreame'); + assert.equal(child.food, 'icecreame'); + } }); } diff --git a/packages/ember-metal/tests/accessors/set_path_test.js b/packages/ember-metal/tests/accessors/set_path_test.js index 7b941f05055..ae04193517b 100644 --- a/packages/ember-metal/tests/accessors/set_path_test.js +++ b/packages/ember-metal/tests/accessors/set_path_test.js @@ -4,6 +4,7 @@ import { trySet, get } from '../..'; +import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; let originalLookup = context.lookup; let lookup; @@ -25,55 +26,66 @@ function commonTeardown() { obj = null; } -QUnit.module('set with path', { - setup: commonSetup, - teardown: commonTeardown -}); +moduleFor('set with path', class extends AbstractTestCase { + constructor() { + super(); + commonSetup(); + } -QUnit.test('[Foo, bar] -> Foo.bar', function() { - lookup.Foo = { toString() { return 'Foo'; } }; // Behave like an Ember.Namespace + teardown() { + commonTeardown(); + } - set(lookup.Foo, 'bar', 'baz'); - equal(get(lookup.Foo, 'bar'), 'baz'); -}); + ['@test [Foo, bar] -> Foo.bar'](assert) { + lookup.Foo = { toString() { return 'Foo'; } }; // Behave like an Ember.Namespace -// .......................................................... -// -// LOCAL PATHS + set(lookup.Foo, 'bar', 'baz'); + assert.equal(get(lookup.Foo, 'bar'), 'baz'); + } -QUnit.test('[obj, foo] -> obj.foo', function() { - set(obj, 'foo', 'BAM'); - equal(get(obj, 'foo'), 'BAM'); -}); + // .......................................................... + // + // LOCAL PATHS + + ['@test [obj, foo] -> obj.foo'](assert) { + set(obj, 'foo', 'BAM'); + assert.equal(get(obj, 'foo'), 'BAM'); + } -QUnit.test('[obj, foo.bar] -> obj.foo.bar', function() { - set(obj, 'foo.bar', 'BAM'); - equal(get(obj, 'foo.bar'), 'BAM'); + ['@test [obj, foo.bar] -> obj.foo.bar'](assert) { + set(obj, 'foo.bar', 'BAM'); + assert.equal(get(obj, 'foo.bar'), 'BAM'); + } }); -// .......................................................... -// DEPRECATED -// +moduleFor('set with path - deprecated', class extends AbstractTestCase { + constructor() { + super(); + commonSetup(); + } -QUnit.module('set with path - deprecated', { - setup: commonSetup, - teardown: commonTeardown -}); + teardown() { + commonTeardown(); + } -QUnit.test('[obj, bla.bla] gives a proper exception message', function() { - let exceptionMessage = 'Property set failed: object in path \"bla\" could not be found or was destroyed.'; - try { - set(obj, 'bla.bla', 'BAM'); - } catch (ex) { - equal(ex.message, exceptionMessage); + // .......................................................... + // DEPRECATED + // + ['@test [obj, bla.bla] gives a proper exception message'](assert) { + let exceptionMessage = 'Property set failed: object in path \"bla\" could not be found or was destroyed.'; + try { + set(obj, 'bla.bla', 'BAM'); + } catch (ex) { + assert.equal(ex.message, exceptionMessage); + } } -}); -QUnit.test('[obj, foo.baz.bat] -> EXCEPTION', function() { - throws(() => set(obj, 'foo.baz.bat', 'BAM')); -}); + ['@test [obj, foo.baz.bat] -> EXCEPTION'](assert) { + assert.throws(() => set(obj, 'foo.baz.bat', 'BAM')); + } -QUnit.test('[obj, foo.baz.bat] -> EXCEPTION', function() { - trySet(obj, 'foo.baz.bat', 'BAM'); - ok(true, 'does not raise'); + ['@test [obj, foo.baz.bat] -> EXCEPTION'](assert) { + trySet(obj, 'foo.baz.bat', 'BAM'); + assert.ok(true, 'does not raise'); + } }); diff --git a/packages/ember-metal/tests/accessors/set_test.js b/packages/ember-metal/tests/accessors/set_test.js index 39a52ad64ec..b83949dfbdf 100644 --- a/packages/ember-metal/tests/accessors/set_test.js +++ b/packages/ember-metal/tests/accessors/set_test.js @@ -3,85 +3,87 @@ import { set, setHasViews } from '../..'; +import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; -QUnit.module('set', { +moduleFor('set', class extends AbstractTestCase { teardown() { setHasViews(() => false); } -}); -QUnit.test('should set arbitrary properties on an object', function() { - let obj = { - string: 'string', - number: 23, - boolTrue: true, - boolFalse: false, - nullValue: null, - undefinedValue: undefined - }; - - let newObj = { - undefinedValue: 'emberjs' - }; - - for (let key in obj) { - if (!obj.hasOwnProperty(key)) { - continue; + ['@test should set arbitrary properties on an object'](assert) { + let obj = { + string: 'string', + number: 23, + boolTrue: true, + boolFalse: false, + nullValue: null, + undefinedValue: undefined + }; + + let newObj = { + undefinedValue: 'emberjs' + }; + + for (let key in obj) { + if (!obj.hasOwnProperty(key)) { + continue; + } + + assert.equal(set(newObj, key, obj[key]), obj[key], 'should return value'); + assert.equal(get(newObj, key), obj[key], 'should set value'); } - - equal(set(newObj, key, obj[key]), obj[key], 'should return value'); - equal(get(newObj, key), obj[key], 'should set value'); } -}); -QUnit.test('should call setUnknownProperty if defined and value is undefined', function() { - let obj = { - count: 0, + ['@test should call setUnknownProperty if defined and value is undefined'](assert) { + let obj = { + count: 0, - unknownProperty() { - ok(false, 'should not invoke unknownProperty if setUnknownProperty is defined'); - }, + unknownProperty() { + assert.ok(false, 'should not invoke unknownProperty if setUnknownProperty is defined'); + }, - setUnknownProperty(key, value) { - equal(key, 'foo', 'should pass key'); - equal(value, 'BAR', 'should pass key'); - this.count++; - return 'FOO'; - } - }; + setUnknownProperty(key, value) { + assert.equal(key, 'foo', 'should pass key'); + assert.equal(value, 'BAR', 'should pass key'); + this.count++; + return 'FOO'; + } + }; - equal(set(obj, 'foo', 'BAR'), 'BAR', 'should return set value'); - equal(obj.count, 1, 'should have invoked'); -}); + assert.equal(set(obj, 'foo', 'BAR'), 'BAR', 'should return set value'); + assert.equal(obj.count, 1, 'should have invoked'); + } -QUnit.test('warn on attempts to call set with undefined as object', function() { - expectAssertion(() => set(undefined, 'aProperty', 'BAM'), /Cannot call set with 'aProperty' on an undefined object./); -}); + ['@test warn on attempts to call set with undefined as object']() { + expectAssertion(() => set(undefined, 'aProperty', 'BAM'), /Cannot call set with 'aProperty' on an undefined object./); + } -QUnit.test('warn on attempts to call set with null as object', function() { - expectAssertion(() => set(null, 'aProperty', 'BAM'), /Cannot call set with 'aProperty' on an undefined object./); -}); + ['@test warn on attempts to call set with null as object']() { + expectAssertion(() => set(null, 'aProperty', 'BAM'), /Cannot call set with 'aProperty' on an undefined object./); + } -QUnit.test('warn on attempts to use set with an unsupported property path', function() { - let obj = {}; - expectAssertion(() => set(obj, null, 42), /The key provided to set must be a string, you passed null/); - expectAssertion(() => set(obj, NaN, 42), /The key provided to set must be a string, you passed NaN/); - expectAssertion(() => set(obj, undefined, 42), /The key provided to set must be a string, you passed undefined/); - expectAssertion(() => set(obj, false, 42), /The key provided to set must be a string, you passed false/); - expectAssertion(() => set(obj, 42, 42), /The key provided to set must be a string, you passed 42/); -}); + ['@test warn on attempts to use set with an unsupported property path']() { + let obj = {}; + expectAssertion(() => set(obj, null, 42), /The key provided to set must be a string, you passed null/); + expectAssertion(() => set(obj, NaN, 42), /The key provided to set must be a string, you passed NaN/); + expectAssertion(() => set(obj, undefined, 42), /The key provided to set must be a string, you passed undefined/); + expectAssertion(() => set(obj, false, 42), /The key provided to set must be a string, you passed false/); + expectAssertion(() => set(obj, 42, 42), /The key provided to set must be a string, you passed 42/); + } -QUnit.test('warn on attempts of calling set on a destroyed object', function() { - let obj = { isDestroyed: true }; + ['@test warn on attempts of calling set on a destroyed object']() { + let obj = { isDestroyed: true }; - expectAssertion(() => set(obj, 'favoriteFood', 'hot dogs'), 'calling set on destroyed object: [object Object].favoriteFood = hot dogs'); -}); + expectAssertion(() => set(obj, 'favoriteFood', 'hot dogs'), 'calling set on destroyed object: [object Object].favoriteFood = hot dogs'); + } -QUnit.test('does not trigger auto-run assertion for objects that have not been tagged', function(assert) { - setHasViews(() => true); - let obj = {}; + ['@test does not trigger auto-run assertion for objects that have not been tagged'](assert) { + setHasViews(() => true); + let obj = {}; - set(obj, 'foo', 'bar'); + set(obj, 'foo', 'bar'); - assert.equal(obj.foo, 'bar'); + assert.equal(obj.foo, 'bar'); + } }); +