diff --git a/.eslintrc.js b/.eslintrc.js index 6b1d6d2..87a4242 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -49,15 +49,6 @@ module.exports = { }) }, - // test files - { - files: ['tests/**/*.js'], - excludedFiles: ['tests/dummy/**/*.js'], - env: { - embertest: true - } - }, - { files: ['node-tests/**/*.js'], env: { diff --git a/package-lock.json b/package-lock.json index 2294b66..328fb36 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3624,6 +3624,26 @@ "ember-cli-babel": "6.12.0" } }, + "ember-maybe-import-regenerator": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/ember-maybe-import-regenerator/-/ember-maybe-import-regenerator-0.1.6.tgz", + "integrity": "sha1-NdQYKK+m1qWbwNo85H80xXPXdso=", + "dev": true, + "requires": { + "broccoli-funnel": "1.2.0", + "broccoli-merge-trees": "1.2.4", + "ember-cli-babel": "6.12.0", + "regenerator-runtime": "0.9.6" + }, + "dependencies": { + "regenerator-runtime": { + "version": "0.9.6", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.9.6.tgz", + "integrity": "sha1-0z65XQ0gAaS+OWWXB8UbDLcc4Ck=", + "dev": true + } + } + }, "ember-qunit": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/ember-qunit/-/ember-qunit-3.4.0.tgz", diff --git a/package.json b/package.json index aeb9dd7..541bdab 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "ember-disable-prototype-extensions": "^1.1.2", "ember-load-initializers": "^1.0.0", "ember-macro-test-helpers": "^3.1.0", + "ember-maybe-import-regenerator": "^0.1.6", "ember-resolver": "^4.0.0", "ember-sinon": "^2.1.0", "ember-source": "~3.1.0", diff --git a/tests/acceptance/application-test.js b/tests/acceptance/application-test.js index 2469721..7b8722a 100644 --- a/tests/acceptance/application-test.js +++ b/tests/acceptance/application-test.js @@ -1,44 +1,35 @@ -import { test } from 'qunit'; -import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; +import { click, find, visit } from '@ember/test-helpers'; +import { module, test } from 'qunit'; +import { setupApplicationTest } from 'ember-qunit'; -moduleForAcceptance('Acceptance | application'); +module('Acceptance | application', function(hooks) { + setupApplicationTest(hooks); -test('double render failing test', function(assert) { - visit('/double-render'); + test('double render failing test', async function(assert) { + await visit('/double-render'); - andThen(function() { - assert.equal(find('.computed').text(), 'test val 1'); - }); + assert.equal(find('.computed').textContent, 'test val 1'); - click('button'); + await click('button'); - andThen(function() { - assert.equal(find('.computed').text(), 'test val 2'); - }); + assert.equal(find('.computed').textContent, 'test val 2'); - click('button'); + await click('button'); - andThen(function() { - assert.equal(find('.computed').text(), 'test val 3'); + assert.equal(find('.computed').textContent, 'test val 3'); }); -}); -test('no rerender failing test', function(assert) { - visit('/no-rerender'); + test('no rerender failing test', async function(assert) { + await visit('/no-rerender'); - andThen(function() { - assert.equal(find('.items').text(), 1); - }); + assert.equal(find('.items').textContent, 1); - click('button'); + await click('button'); - andThen(function() { - assert.equal(find('.items').text(), 0); - }); + assert.equal(find('.items').textContent, 0); - click('button'); + await click('button'); - andThen(function() { - assert.equal(find('.items').text(), 1); + assert.equal(find('.items').textContent, 1); }); }); diff --git a/tests/helpers/.gitkeep b/tests/helpers/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tests/helpers/destroy-app.js b/tests/helpers/destroy-app.js deleted file mode 100644 index e7f983b..0000000 --- a/tests/helpers/destroy-app.js +++ /dev/null @@ -1,5 +0,0 @@ -import { run } from '@ember/runloop'; - -export default function destroyApp(application) { - run(application, 'destroy'); -} diff --git a/tests/helpers/module-for-acceptance.js b/tests/helpers/module-for-acceptance.js deleted file mode 100644 index 90a93ba..0000000 --- a/tests/helpers/module-for-acceptance.js +++ /dev/null @@ -1,21 +0,0 @@ -import { module } from 'qunit'; -import { resolve } from 'rsvp'; -import startApp from '../helpers/start-app'; -import destroyApp from '../helpers/destroy-app'; - -export default function(name, options = {}) { - module(name, { - beforeEach() { - this.application = startApp(); - - if (options.beforeEach) { - return options.beforeEach.apply(this, arguments); - } - }, - - afterEach() { - let afterEach = options.afterEach && options.afterEach.apply(this, arguments); - return resolve(afterEach).then(() => destroyApp(this.application)); - } - }); -} diff --git a/tests/helpers/start-app.js b/tests/helpers/start-app.js deleted file mode 100644 index 99d35dc..0000000 --- a/tests/helpers/start-app.js +++ /dev/null @@ -1,17 +0,0 @@ -import Application from '../../app'; -import config from '../../config/environment'; -import { merge } from '@ember/polyfills'; -import { run } from '@ember/runloop'; - -export default function startApp(attrs) { - let attributes = merge({}, config.APP); - attributes.autoboot = true; - attributes = merge(attributes, attrs); // use defaults, but you can override; - - return run(() => { - let application = Application.create(attributes); - application.setupForTesting(); - application.injectTestHelpers(); - return application; - }); -} diff --git a/tests/integration/computed-test.js b/tests/integration/computed-test.js index 6e07f5b..be8cd4b 100644 --- a/tests/integration/computed-test.js +++ b/tests/integration/computed-test.js @@ -14,323 +14,323 @@ const newValue = 'new value test'; let getCallback; let setCallback; -module('Integration | computed', { - beforeEach() { +module('Integration | computed', function(hooks) { + hooks.beforeEach(function() { getCallback = sinon.stub().returns(getReturnValue); setCallback = sinon.stub().returns(setReturnValue); - } -}); + }); -function alias(key) { - return computed(key, val => val); -} - -[ - { - name: 'computed', - computed - }, - { - name: 'computedUnsafe', - computed: computedUnsafe - } -].forEach(({ name, computed }) => { - function test(title, callback) { - namedTest(name, title, callback); + function alias(key) { + return computed(key, val => val); } - test('works with no key', function(assert) { - compute({ - assert, - computed: computed(getCallback), - strictEqual: getReturnValue - }); - }); + [ + { + name: 'computed', + computed + }, + { + name: 'computedUnsafe', + computed: computedUnsafe + } + ].forEach(({ name, computed }) => { + function test(title, callback) { + namedTest(name, title, callback); + } - test('works with undefined key', function(assert) { - compute({ - assert, - computed: computed('key1', getCallback), - strictEqual: getReturnValue + test('works with no key', function(assert) { + compute({ + assert, + computed: computed(getCallback), + strictEqual: getReturnValue + }); }); - }); - test('throws without a func param', function(assert) { - let func = () => compute({ - computed: computed() + test('works with undefined key', function(assert) { + compute({ + assert, + computed: computed('key1', getCallback), + strictEqual: getReturnValue + }); }); - assert.throws(func); - }); + test('throws without a func param', function(assert) { + let func = () => compute({ + computed: computed() + }); - test('function syntax: uses the right context when getting', function(assert) { - let { subject } = compute({ - computed: computed(getCallback) + assert.throws(func); }); - assert.strictEqual(getCallback.thisValues[0], subject); - }); + test('function syntax: uses the right context when getting', function(assert) { + let { subject } = compute({ + computed: computed(getCallback) + }); - test('function syntax: passes the values when getting', function(assert) { - compute({ - computed: computed('key1', alias('key2'), getCallback), - properties: { - key1: '123', - key2: '456' - } + assert.strictEqual(getCallback.thisValues[0], subject); }); - assert.deepEqual(getCallback.args[1], ['123', '456']); - }); + test('function syntax: passes the values when getting', function(assert) { + compute({ + computed: computed('key1', alias('key2'), getCallback), + properties: { + key1: '123', + key2: '456' + } + }); - test('function syntax: doesn\'t call when setting', function(assert) { - let { subject } = compute({ - computed: computed(getCallback) + assert.deepEqual(getCallback.args[1], ['123', '456']); }); - getCallback.reset(); + test('function syntax: doesn\'t call when setting', function(assert) { + let { subject } = compute({ + computed: computed(getCallback) + }); - subject.set('computed', newValue); + getCallback.reset(); - assert.notOk(getCallback.called); - }); + subject.set('computed', newValue); - test('function syntax: preserves set value', function(assert) { - let { subject } = compute({ - computed: computed(getCallback) + assert.notOk(getCallback.called); }); - getCallback.reset(); + test('function syntax: preserves set value', function(assert) { + let { subject } = compute({ + computed: computed(getCallback) + }); - subject.set('computed', newValue); + getCallback.reset(); - assert.strictEqual(subject.get('computed'), newValue); - }); + subject.set('computed', newValue); - test('object syntax: uses the right context when getting', function(assert) { - let { subject } = compute({ - computed: computed({ - get: getCallback - }) + assert.strictEqual(subject.get('computed'), newValue); }); - assert.strictEqual(getCallback.thisValues[0], subject); - }); + test('object syntax: uses the right context when getting', function(assert) { + let { subject } = compute({ + computed: computed({ + get: getCallback + }) + }); - test('object syntax: passes the values when getting', function(assert) { - compute({ - computed: computed('key1', alias('key2'), { - get: getCallback - }), - properties: { - key1: '123', - key2: '456' - } + assert.strictEqual(getCallback.thisValues[0], subject); }); - assert.deepEqual(getCallback.args[1], ['123', '456']); - }); - - test('object syntax: uses the right context when setting', function(assert) { - let { subject } = compute({ - computed: computed({ - get: getCallback, - set: setCallback - }) + test('object syntax: passes the values when getting', function(assert) { + compute({ + computed: computed('key1', alias('key2'), { + get: getCallback + }), + properties: { + key1: '123', + key2: '456' + } + }); + + assert.deepEqual(getCallback.args[1], ['123', '456']); }); - subject.set('computed', newValue); + test('object syntax: uses the right context when setting', function(assert) { + let { subject } = compute({ + computed: computed({ + get: getCallback, + set: setCallback + }) + }); - assert.strictEqual(setCallback.thisValues[0], subject); - }); + subject.set('computed', newValue); - test('object syntax: passes the values when setting', function(assert) { - let { subject } = compute({ - computed: computed('key1', alias('key2'), { - get: getCallback, - set: setCallback - }), - properties: { - key1: '123', - key2: '456' - } + assert.strictEqual(setCallback.thisValues[0], subject); }); - subject.set('computed', newValue); - - assert.deepEqual(setCallback.args, [[newValue, '123', '456']]); - }); - - test('object syntax: preserves set value', function(assert) { - let { subject } = compute({ - computed: computed({ - get: getCallback, - set: setCallback - }) + test('object syntax: passes the values when setting', function(assert) { + let { subject } = compute({ + computed: computed('key1', alias('key2'), { + get: getCallback, + set: setCallback + }), + properties: { + key1: '123', + key2: '456' + } + }); + + subject.set('computed', newValue); + + assert.deepEqual(setCallback.args, [[newValue, '123', '456']]); }); - getCallback.reset(); + test('object syntax: preserves set value', function(assert) { + let { subject } = compute({ + computed: computed({ + get: getCallback, + set: setCallback + }) + }); - subject.set('computed', newValue); + getCallback.reset(); - assert.strictEqual(subject.get('computed'), setReturnValue); - }); -}); + subject.set('computed', newValue); -namedTest('computed', 'function syntax: resolves array [] keys', function(assert) { - compute({ - computed: computed('key1.[]', getCallback), - properties: { - key1: '123' - } + assert.strictEqual(subject.get('computed'), setReturnValue); + }); }); - assert.deepEqual(getCallback.args[1], ['123']); -}); + namedTest('computed', 'function syntax: resolves array [] keys', function(assert) { + compute({ + computed: computed('key1.[]', getCallback), + properties: { + key1: '123' + } + }); -namedTest('computed', 'function syntax: resolves ArrayProxy []', function(assert) { - compute({ - baseClass: ArrayProxy, - computed: computed('[]', getCallback), - properties: { - content: emberA(['123']) - } + assert.deepEqual(getCallback.args[1], ['123']); }); - assert.deepEqual(getCallback.args[1][0].toArray(), ['123']); -}); + namedTest('computed', 'function syntax: resolves ArrayProxy []', function(assert) { + compute({ + baseClass: ArrayProxy, + computed: computed('[]', getCallback), + properties: { + content: emberA(['123']) + } + }); -namedTest('computed', 'function syntax: resolves expand properties []', function(assert) { - compute({ - computed: computed('{key1.[],key2}', getCallback), - properties: { - key1: '123', - key2: '456' - } + assert.deepEqual(getCallback.args[1][0].toArray(), ['123']); }); - assert.deepEqual(getCallback.args[1], ['123', '456']); -}); + namedTest('computed', 'function syntax: resolves expand properties []', function(assert) { + compute({ + computed: computed('{key1.[],key2}', getCallback), + properties: { + key1: '123', + key2: '456' + } + }); -namedTest('computed', 'function syntax: resolves array @each keys', function(assert) { - compute({ - computed: computed('key1.@each.key2', getCallback), - properties: { - key1: '123' - } + assert.deepEqual(getCallback.args[1], ['123', '456']); }); - assert.deepEqual(getCallback.args[1], ['123']); -}); + namedTest('computed', 'function syntax: resolves array @each keys', function(assert) { + compute({ + computed: computed('key1.@each.key2', getCallback), + properties: { + key1: '123' + } + }); -namedTest('computed', 'function syntax: resolves ArrayProxy @each', function(assert) { - compute({ - baseClass: ArrayProxy, - computed: computed('@each.key1', getCallback), - properties: { - content: emberA([{ key1: '123' }]) - } + assert.deepEqual(getCallback.args[1], ['123']); }); - assert.deepEqual(getCallback.args[1][0].toArray(), [{ key1: '123' }]); -}); + namedTest('computed', 'function syntax: resolves ArrayProxy @each', function(assert) { + compute({ + baseClass: ArrayProxy, + computed: computed('@each.key1', getCallback), + properties: { + content: emberA([{ key1: '123' }]) + } + }); -namedTest('computed', 'function syntax: resolves expand properties @each', function(assert) { - compute({ - computed: computed('{key1.@each.key3,key2}', getCallback), - properties: { - key1: '123', - key2: '456' - } + assert.deepEqual(getCallback.args[1][0].toArray(), [{ key1: '123' }]); }); - assert.deepEqual(getCallback.args[1], ['123', '456']); -}); + namedTest('computed', 'function syntax: resolves expand properties @each', function(assert) { + compute({ + computed: computed('{key1.@each.key3,key2}', getCallback), + properties: { + key1: '123', + key2: '456' + } + }); -namedTest('computed', 'function syntax: expands properties', function(assert) { - compute({ - computed: computed('{key1,key2}', getCallback), - properties: { - key1: '123', - key2: '456' - } + assert.deepEqual(getCallback.args[1], ['123', '456']); }); - assert.deepEqual(getCallback.args[1], ['123', '456']); -}); + namedTest('computed', 'function syntax: expands properties', function(assert) { + compute({ + computed: computed('{key1,key2}', getCallback), + properties: { + key1: '123', + key2: '456' + } + }); -namedTest('computed', 'function syntax: passes undefined if property doesn\'t exist', function(assert) { - compute({ - computed: computed('key1', getCallback) + assert.deepEqual(getCallback.args[1], ['123', '456']); }); - assert.deepEqual(getCallback.args, [[undefined]]); -}); + namedTest('computed', 'function syntax: passes undefined if property doesn\'t exist', function(assert) { + compute({ + computed: computed('key1', getCallback) + }); -namedTest('computed', 'object syntax: resolves array [] keys', function(assert) { - compute({ - computed: computed('key1.[]', { - get: getCallback - }), - properties: { - key1: '123' - } + assert.deepEqual(getCallback.args, [[undefined]]); }); - assert.deepEqual(getCallback.args[1], ['123']); -}); + namedTest('computed', 'object syntax: resolves array [] keys', function(assert) { + compute({ + computed: computed('key1.[]', { + get: getCallback + }), + properties: { + key1: '123' + } + }); -namedTest('computed', 'object syntax: resolves array @each keys', function(assert) { - compute({ - computed: computed('key1.@each.key2', { - get: getCallback - }), - properties: { - key1: '123' - } + assert.deepEqual(getCallback.args[1], ['123']); }); - assert.deepEqual(getCallback.args[1], ['123']); -}); + namedTest('computed', 'object syntax: resolves array @each keys', function(assert) { + compute({ + computed: computed('key1.@each.key2', { + get: getCallback + }), + properties: { + key1: '123' + } + }); -namedTest('computed', 'object syntax: expands properties', function(assert) { - compute({ - computed: computed('{key1,key2}', { - get: getCallback - }), - properties: { - key1: '123', - key2: '456' - } + assert.deepEqual(getCallback.args[1], ['123']); }); - assert.deepEqual(getCallback.args[1], ['123', '456']); -}); + namedTest('computed', 'object syntax: expands properties', function(assert) { + compute({ + computed: computed('{key1,key2}', { + get: getCallback + }), + properties: { + key1: '123', + key2: '456' + } + }); -namedTest('computed', 'object syntax: passes undefined if property doesn\'t exist', function(assert) { - compute({ - computed: computed('key1', { - get: getCallback - }) + assert.deepEqual(getCallback.args[1], ['123', '456']); }); - assert.deepEqual(getCallback.args, [[undefined]]); -}); + namedTest('computed', 'object syntax: passes undefined if property doesn\'t exist', function(assert) { + compute({ + computed: computed('key1', { + get: getCallback + }) + }); -namedTest('computedUnsafe', 'function syntax: passes literal if property doesn\'t exist', function(assert) { - compute({ - computed: computedUnsafe('literal with spaces', getCallback) + assert.deepEqual(getCallback.args, [[undefined]]); }); - assert.deepEqual(getCallback.args, [['literal with spaces']]); -}); + namedTest('computedUnsafe', 'function syntax: passes literal if property doesn\'t exist', function(assert) { + compute({ + computed: computedUnsafe('literal with spaces', getCallback) + }); -namedTest('computedUnsafe', 'object syntax: passes literal if property doesn\'t exist', function(assert) { - compute({ - computed: computedUnsafe('literal with spaces', { - get: getCallback - }) + assert.deepEqual(getCallback.args, [['literal with spaces']]); }); - assert.deepEqual(getCallback.args, [['literal with spaces']]); + namedTest('computedUnsafe', 'object syntax: passes literal if property doesn\'t exist', function(assert) { + compute({ + computed: computedUnsafe('literal with spaces', { + get: getCallback + }) + }); + + assert.deepEqual(getCallback.args, [['literal with spaces']]); + }); }); diff --git a/tests/integration/create-class-computed-test.js b/tests/integration/create-class-computed-test.js index aaede91..2a46ea4 100644 --- a/tests/integration/create-class-computed-test.js +++ b/tests/integration/create-class-computed-test.js @@ -14,8 +14,8 @@ const { WeakMap } = Ember; let PROPERTIES; let filterBy; -module('Integration | create class computed', { - beforeEach() { +module('Integration | create class computed', function(hooks) { + hooks.beforeEach(function() { PROPERTIES = new WeakMap(); filterBy = createClassComputed( @@ -31,331 +31,331 @@ module('Integration | create class computed', { }); } ); - } -}); - -test('it initially calculates correctly', function(assert) { - let array = emberA([ - EmberObject.create({ test: 'val1' }), - EmberObject.create({ test: 'val2' }) - ]); - - let { subject } = compute({ - computed: filterBy('array', 'key', 'value'), - properties: { - array, - key: 'test', - value: 'val1' - } }); - assert.equal(subject.get('computed.length'), 1); -}); + test('it initially calculates correctly', function(assert) { + let array = emberA([ + EmberObject.create({ test: 'val1' }), + EmberObject.create({ test: 'val2' }) + ]); -test('it responds to array property value changes internally', function(assert) { - let array = emberA([ - EmberObject.create({ test: 'val1' }), - EmberObject.create({ test: 'val2' }) - ]); - - let { subject } = compute({ - computed: filterBy('array', 'key', 'value'), - properties: { - array, - key: 'test', - value: 'val1' - } + let { subject } = compute({ + computed: filterBy('array', 'key', 'value'), + properties: { + array, + key: 'test', + value: 'val1' + } + }); + + assert.equal(subject.get('computed.length'), 1); }); - array.set('1.test', 'val1'); + test('it responds to array property value changes internally', function(assert) { + let array = emberA([ + EmberObject.create({ test: 'val1' }), + EmberObject.create({ test: 'val2' }) + ]); - assert.equal(subject.get('computed.length'), 2); -}); + let { subject } = compute({ + computed: filterBy('array', 'key', 'value'), + properties: { + array, + key: 'test', + value: 'val1' + } + }); -test('it responds to array property value changes externally', function(assert) { - let array = emberA([ - EmberObject.create({ test: 'val1' }), - EmberObject.create({ test: 'val2' }) - ]); - - let { subject } = compute({ - computed: filterBy('array.@each.test', 'key', 'value'), - properties: { - array, - value: 'val1' - } + array.set('1.test', 'val1'); + + assert.equal(subject.get('computed.length'), 2); }); - array.set('1.test', 'val1'); + test('it responds to array property value changes externally', function(assert) { + let array = emberA([ + EmberObject.create({ test: 'val1' }), + EmberObject.create({ test: 'val2' }) + ]); - assert.equal(subject.get('computed.length'), 2); -}); + let { subject } = compute({ + computed: filterBy('array.@each.test', 'key', 'value'), + properties: { + array, + value: 'val1' + } + }); -test('it responds to array property value changes using raw array', function(assert) { - let array = emberA([ - EmberObject.create({ test: 'val1' }), - EmberObject.create({ test: 'val2' }) - ]); + array.set('1.test', 'val1'); - let { subject } = compute({ - computed: filterBy(array, raw('test'), raw('val1')) + assert.equal(subject.get('computed.length'), 2); }); - array.set('1.test', 'val1'); + test('it responds to array property value changes using raw array', function(assert) { + let array = emberA([ + EmberObject.create({ test: 'val1' }), + EmberObject.create({ test: 'val2' }) + ]); - assert.equal(subject.get('computed.length'), 2); -}); + let { subject } = compute({ + computed: filterBy(array, raw('test'), raw('val1')) + }); -test('it responds to property value changes using brace expansion', function(assert) { - let array = emberA([ - EmberObject.create({ test: 'val1' }), - EmberObject.create({ test: 'val1' }) - ]); + array.set('1.test', 'val1'); - let { subject } = compute({ - computed: filterBy('obj.{array,key,value}'), - properties: { - obj: EmberObject.create({ - array, - key: 'test', - value: 'val2' - }) - } + assert.equal(subject.get('computed.length'), 2); }); - subject.set('obj.value', 'val1'); + test('it responds to property value changes using brace expansion', function(assert) { + let array = emberA([ + EmberObject.create({ test: 'val1' }), + EmberObject.create({ test: 'val1' }) + ]); + + let { subject } = compute({ + computed: filterBy('obj.{array,key,value}'), + properties: { + obj: EmberObject.create({ + array, + key: 'test', + value: 'val2' + }) + } + }); - assert.equal(subject.get('computed.length'), 2); -}); + subject.set('obj.value', 'val1'); -test('it responds to array length changes', function(assert) { - let array = emberA([ - EmberObject.create({ test: 'val1' }), - EmberObject.create({ test: 'val2' }) - ]); - - let { subject } = compute({ - computed: filterBy('array', 'key', 'value'), - properties: { - array, - key: 'test', - value: 'val1' - } + assert.equal(subject.get('computed.length'), 2); }); - array.pushObject(EmberObject.create({ test: 'val1' })); + test('it responds to array length changes', function(assert) { + let array = emberA([ + EmberObject.create({ test: 'val1' }), + EmberObject.create({ test: 'val2' }) + ]); - assert.equal(subject.get('computed.length'), 2); -}); + let { subject } = compute({ + computed: filterBy('array', 'key', 'value'), + properties: { + array, + key: 'test', + value: 'val1' + } + }); -test('it responds to property key changes', function(assert) { - let array = emberA([ - EmberObject.create({ test: 'val1' }), - EmberObject.create({ test: 'val2' }) - ]); - - let { subject } = compute({ - computed: filterBy('array', 'key', 'value'), - properties: { - array, - key: 'test2', - value: 'val1' - } + array.pushObject(EmberObject.create({ test: 'val1' })); + + assert.equal(subject.get('computed.length'), 2); }); - subject.set('key', 'test'); + test('it responds to property key changes', function(assert) { + let array = emberA([ + EmberObject.create({ test: 'val1' }), + EmberObject.create({ test: 'val2' }) + ]); - assert.equal(subject.get('computed.length'), 1); -}); + let { subject } = compute({ + computed: filterBy('array', 'key', 'value'), + properties: { + array, + key: 'test2', + value: 'val1' + } + }); -test('it responds to property value changes', function(assert) { - let array = emberA([ - EmberObject.create({ test: 'val1' }), - EmberObject.create({ test: 'val1' }) - ]); - - let { subject } = compute({ - computed: filterBy('array', 'key', 'value'), - properties: { - array, - key: 'test', - value: 'val2' - } + subject.set('key', 'test'); + + assert.equal(subject.get('computed.length'), 1); }); - subject.set('value', 'val1'); + test('it responds to property value changes', function(assert) { + let array = emberA([ + EmberObject.create({ test: 'val1' }), + EmberObject.create({ test: 'val1' }) + ]); - assert.equal(subject.get('computed.length'), 2); -}); + let { subject } = compute({ + computed: filterBy('array', 'key', 'value'), + properties: { + array, + key: 'test', + value: 'val2' + } + }); + + subject.set('value', 'val1'); -test('composing: macros still compute inside', function(assert) { - let array1 = emberA([ - EmberObject.create({ test: 'val1' }), - EmberObject.create({ test: 'val1' }) - ]); - let array2 = emberA([ - EmberObject.create({ test: 'val1' }), - EmberObject.create({ test: 'val2' }) - ]); - - let { subject } = compute({ - computed: filterBy(computed('innerKey', innerKey => innerKey ? array1 : array2), 'key', 'value'), - properties: { - innerKey: true, - key: 'test', - value: 'val1' - } + assert.equal(subject.get('computed.length'), 2); }); - assert.equal(subject.get('computed.length'), 2); + test('composing: macros still compute inside', function(assert) { + let array1 = emberA([ + EmberObject.create({ test: 'val1' }), + EmberObject.create({ test: 'val1' }) + ]); + let array2 = emberA([ + EmberObject.create({ test: 'val1' }), + EmberObject.create({ test: 'val2' }) + ]); + + let { subject } = compute({ + computed: filterBy(computed('innerKey', innerKey => innerKey ? array1 : array2), 'key', 'value'), + properties: { + innerKey: true, + key: 'test', + value: 'val1' + } + }); - subject.set('innerKey', false); + assert.equal(subject.get('computed.length'), 2); - assert.equal(subject.get('computed.length'), 1); -}); + subject.set('innerKey', false); -test('composing: it responds to array property value changes', function(assert) { - let array = emberA([ - EmberObject.create({ test: 'val1' }), - EmberObject.create({ test: 'val2' }) - ]); - - let { subject } = compute({ - computed: filterBy(computed(() => array), 'key', 'value'), - properties: { - key: 'test', - value: 'val1' - } + assert.equal(subject.get('computed.length'), 1); }); - assert.equal(subject.get('computed.length'), 1); + test('composing: it responds to array property value changes', function(assert) { + let array = emberA([ + EmberObject.create({ test: 'val1' }), + EmberObject.create({ test: 'val2' }) + ]); - array.set('1.test', 'val1'); + let { subject } = compute({ + computed: filterBy(computed(() => array), 'key', 'value'), + properties: { + key: 'test', + value: 'val1' + } + }); - assert.equal(subject.get('computed.length'), 2); -}); + assert.equal(subject.get('computed.length'), 1); -test('composing: it responds to property key changes', function(assert) { - let array = emberA([ - EmberObject.create({ test: 'val1' }), - EmberObject.create({ test: 'val2' }) - ]); - - let { subject } = compute({ - computed: filterBy(computed(() => array), 'key', 'value'), - properties: { - array, - key: 'test2', - value: 'val1' - } + array.set('1.test', 'val1'); + + assert.equal(subject.get('computed.length'), 2); }); - assert.equal(subject.get('computed.length'), 0); + test('composing: it responds to property key changes', function(assert) { + let array = emberA([ + EmberObject.create({ test: 'val1' }), + EmberObject.create({ test: 'val2' }) + ]); - subject.set('key', 'test'); + let { subject } = compute({ + computed: filterBy(computed(() => array), 'key', 'value'), + properties: { + array, + key: 'test2', + value: 'val1' + } + }); - assert.equal(subject.get('computed.length'), 1); -}); + assert.equal(subject.get('computed.length'), 0); -test('composing: it responds to property value changes', function(assert) { - let array = emberA([ - EmberObject.create({ test: 'val1' }), - EmberObject.create({ test: 'val1' }) - ]); - - let { subject } = compute({ - computed: filterBy(computed(() => array), 'key', 'value'), - properties: { - array, - key: 'test', - value: 'val2' - } + subject.set('key', 'test'); + + assert.equal(subject.get('computed.length'), 1); }); - assert.equal(subject.get('computed.length'), 0); + test('composing: it responds to property value changes', function(assert) { + let array = emberA([ + EmberObject.create({ test: 'val1' }), + EmberObject.create({ test: 'val1' }) + ]); - subject.set('value', 'val1'); + let { subject } = compute({ + computed: filterBy(computed(() => array), 'key', 'value'), + properties: { + array, + key: 'test', + value: 'val2' + } + }); - assert.equal(subject.get('computed.length'), 2); -}); + assert.equal(subject.get('computed.length'), 0); -test('composing: macros still compute outside', function(assert) { - let array1 = emberA([ - EmberObject.create({ test: 'val1' }), - EmberObject.create({ test: 'val1' }) - ]); - let array2 = emberA([ - EmberObject.create({ test: 'val1' }), - EmberObject.create({ test: 'val2' }) - ]); - - let { subject } = compute({ - computed: computed(filterBy('array', 'key', 'value'), array => array), - properties: { - array: array1, - key: 'test', - value: 'val1' - } + subject.set('value', 'val1'); + + assert.equal(subject.get('computed.length'), 2); }); - assert.equal(subject.get('computed.length'), 2); + test('composing: macros still compute outside', function(assert) { + let array1 = emberA([ + EmberObject.create({ test: 'val1' }), + EmberObject.create({ test: 'val1' }) + ]); + let array2 = emberA([ + EmberObject.create({ test: 'val1' }), + EmberObject.create({ test: 'val2' }) + ]); + + let { subject } = compute({ + computed: computed(filterBy('array', 'key', 'value'), array => array), + properties: { + array: array1, + key: 'test', + value: 'val1' + } + }); - subject.set('array', array2); + assert.equal(subject.get('computed.length'), 2); - assert.equal(subject.get('computed.length'), 1); -}); + subject.set('array', array2); -test('composing: both macros are class computed', function(assert) { - let array = emberA([ - EmberObject.create({ id: 1, test1: 'val1', test2: 'val1' }), - EmberObject.create({ id: 2, test1: 'val2', test2: 'val1' }), - EmberObject.create({ id: 3, test1: 'val2', test2: 'val2' }) - ]); - - let { subject } = compute({ - computed: filterBy(filterBy('array', 'key1', 'value1'), 'key2', 'value2'), - properties: { - array, - key1: 'test1', - key2: 'test2', - value1: 'val1', - value2: 'val1' - } + assert.equal(subject.get('computed.length'), 1); }); - assert.deepEqual(subject.get('computed').mapBy('id'), [1]); + test('composing: both macros are class computed', function(assert) { + let array = emberA([ + EmberObject.create({ id: 1, test1: 'val1', test2: 'val1' }), + EmberObject.create({ id: 2, test1: 'val2', test2: 'val1' }), + EmberObject.create({ id: 3, test1: 'val2', test2: 'val2' }) + ]); + + let { subject } = compute({ + computed: filterBy(filterBy('array', 'key1', 'value1'), 'key2', 'value2'), + properties: { + array, + key1: 'test1', + key2: 'test2', + value1: 'val1', + value2: 'val1' + } + }); - subject.set('value1', 'val2'); + assert.deepEqual(subject.get('computed').mapBy('id'), [1]); - assert.deepEqual(subject.get('computed').mapBy('id'), [2]); + subject.set('value1', 'val2'); - subject.set('value2', 'val2'); + assert.deepEqual(subject.get('computed').mapBy('id'), [2]); - assert.deepEqual(subject.get('computed').mapBy('id'), [3]); + subject.set('value2', 'val2'); - array.pushObject(EmberObject.create({ id: 4, test1: 'val2', test2: 'val2' })); + assert.deepEqual(subject.get('computed').mapBy('id'), [3]); - assert.deepEqual(subject.get('computed').mapBy('id'), [3, 4]); -}); + array.pushObject(EmberObject.create({ id: 4, test1: 'val2', test2: 'val2' })); -test('it cleans up after destroy', function(assert) { - let array = emberA([ - EmberObject.create({ test: 'val1' }), - EmberObject.create({ test: 'val2' }) - ]); - - let { subject } = compute({ - computed: filterBy('array', 'key', 'value'), - properties: { - array, - key: 'test', - value: 'val1' - } + assert.deepEqual(subject.get('computed').mapBy('id'), [3, 4]); }); - destroy(subject, () => { - array.pushObject(EmberObject.create({ test: 'val1' })); + test('it cleans up after destroy', function(assert) { + let array = emberA([ + EmberObject.create({ test: 'val1' }), + EmberObject.create({ test: 'val2' }) + ]); + + let { subject } = compute({ + computed: filterBy('array', 'key', 'value'), + properties: { + array, + key: 'test', + value: 'val1' + } + }); + + destroy(subject, () => { + array.pushObject(EmberObject.create({ test: 'val1' })); - assert.ok(true); + assert.ok(true); + }); }); }); diff --git a/tests/integration/curried-computed-test.js b/tests/integration/curried-computed-test.js index efe30c2..516d416 100644 --- a/tests/integration/curried-computed-test.js +++ b/tests/integration/curried-computed-test.js @@ -4,28 +4,28 @@ import compute from 'ember-macro-test-helpers/compute'; let computed; -module('Integration | curried computed', { - beforeEach() { +module('Integration | curried computed', function(hooks) { + hooks.beforeEach(function() { computed = curriedComputed((val1, val2) => val1 + val2); - } -}); + }); -test('it curries the computed function', function(assert) { - compute({ - assert, - computed: computed('key1', 'key2'), - properties: { - key1: 1, - key2: 2 - }, - strictEqual: 3 + test('it curries the computed function', function(assert) { + compute({ + assert, + computed: computed('key1', 'key2'), + properties: { + key1: 1, + key2: 2 + }, + strictEqual: 3 + }); }); -}); -test('it creates a read-only computed', function(assert) { - compute({ - assert, - computed: computed(), - assertReadOnly: true + test('it creates a read-only computed', function(assert) { + compute({ + assert, + computed: computed(), + assertReadOnly: true + }); }); }); diff --git a/tests/integration/lazy-computed-test.js b/tests/integration/lazy-computed-test.js index e2b651d..6c7d4fa 100644 --- a/tests/integration/lazy-computed-test.js +++ b/tests/integration/lazy-computed-test.js @@ -12,225 +12,225 @@ const newValue = 'new value test'; let getCallback; let setCallback; -module('Integration | lazy computed', { - beforeEach() { +module('Integration | lazy computed', function(hooks) { + hooks.beforeEach(function() { getCallback = sinon.stub().returns(getReturnValue); setCallback = sinon.stub().returns(setReturnValue); - } -}); + }); -function alias(key) { - return computed(key, val => val); -} + function alias(key) { + return computed(key, val => val); + } -test('works with no key', function(assert) { - compute({ - assert, - computed: lazyComputed(getCallback), - strictEqual: getReturnValue + test('works with no key', function(assert) { + compute({ + assert, + computed: lazyComputed(getCallback), + strictEqual: getReturnValue + }); }); -}); -test('works with undefined key', function(assert) { - compute({ - assert, - computed: lazyComputed('key1', getCallback), - strictEqual: getReturnValue + test('works with undefined key', function(assert) { + compute({ + assert, + computed: lazyComputed('key1', getCallback), + strictEqual: getReturnValue + }); }); -}); -test('throws without a func param', function(assert) { - let func = () => compute({ - computed: lazyComputed() - }); + test('throws without a func param', function(assert) { + let func = () => compute({ + computed: lazyComputed() + }); - assert.throws(func); -}); - -test('function syntax: uses the right context when getting', function(assert) { - let { subject } = compute({ - computed: lazyComputed(getCallback) + assert.throws(func); }); - assert.strictEqual(getCallback.thisValues[0], subject); -}); + test('function syntax: uses the right context when getting', function(assert) { + let { subject } = compute({ + computed: lazyComputed(getCallback) + }); -test('function syntax: passes the keys when getting', function(assert) { - let { subject } = compute({ - computed: lazyComputed('key1', alias('key2'), getCallback) + assert.strictEqual(getCallback.thisValues[0], subject); }); - assert.deepEqual(getCallback.args[0], [ - getValue, - { context: subject, key: 'computed', macro: 'key1' }, - { context: subject, key: 'computed', macro: alias('key2') } - ]); -}); + test('function syntax: passes the keys when getting', function(assert) { + let { subject } = compute({ + computed: lazyComputed('key1', alias('key2'), getCallback) + }); -test('function syntax: doesn\'t call when setting', function(assert) { - let { subject } = compute({ - computed: lazyComputed(getCallback) + assert.deepEqual(getCallback.args[0], [ + getValue, + { context: subject, key: 'computed', macro: 'key1' }, + { context: subject, key: 'computed', macro: alias('key2') } + ]); }); - getCallback.reset(); + test('function syntax: doesn\'t call when setting', function(assert) { + let { subject } = compute({ + computed: lazyComputed(getCallback) + }); - subject.set('computed', newValue); + getCallback.reset(); - assert.notOk(getCallback.called); -}); + subject.set('computed', newValue); -test('function syntax: preserves set value', function(assert) { - let { subject } = compute({ - computed: lazyComputed(getCallback) + assert.notOk(getCallback.called); }); - getCallback.reset(); + test('function syntax: preserves set value', function(assert) { + let { subject } = compute({ + computed: lazyComputed(getCallback) + }); - subject.set('computed', newValue); + getCallback.reset(); - assert.strictEqual(subject.get('computed'), newValue); -}); + subject.set('computed', newValue); -test('object syntax: uses the right context when getting', function(assert) { - let { subject } = compute({ - computed: lazyComputed({ - get: getCallback - }) + assert.strictEqual(subject.get('computed'), newValue); }); - assert.strictEqual(getCallback.thisValues[0], subject); -}); + test('object syntax: uses the right context when getting', function(assert) { + let { subject } = compute({ + computed: lazyComputed({ + get: getCallback + }) + }); -test('object syntax: passes the keys when getting', function(assert) { - let { subject } = compute({ - computed: lazyComputed('key1', alias('key2'), { - get: getCallback - }) + assert.strictEqual(getCallback.thisValues[0], subject); }); - assert.deepEqual(getCallback.args[0], [ - getValue, - { context: subject, key: 'computed', macro: 'key1' }, - { context: subject, key: 'computed', macro: alias('key2') } - ]); -}); + test('object syntax: passes the keys when getting', function(assert) { + let { subject } = compute({ + computed: lazyComputed('key1', alias('key2'), { + get: getCallback + }) + }); -test('object syntax: uses the right context when setting', function(assert) { - let { subject } = compute({ - computed: lazyComputed({ - get: getCallback, - set: setCallback - }) + assert.deepEqual(getCallback.args[0], [ + getValue, + { context: subject, key: 'computed', macro: 'key1' }, + { context: subject, key: 'computed', macro: alias('key2') } + ]); }); - subject.set('computed', newValue); + test('object syntax: uses the right context when setting', function(assert) { + let { subject } = compute({ + computed: lazyComputed({ + get: getCallback, + set: setCallback + }) + }); - assert.strictEqual(setCallback.thisValues[0], subject); -}); + subject.set('computed', newValue); -test('object syntax: passes the keys when setting', function(assert) { - let { subject } = compute({ - computed: lazyComputed('key1', alias('key2'), { - get: getCallback, - set: setCallback - }) + assert.strictEqual(setCallback.thisValues[0], subject); }); - subject.set('computed', newValue); + test('object syntax: passes the keys when setting', function(assert) { + let { subject } = compute({ + computed: lazyComputed('key1', alias('key2'), { + get: getCallback, + set: setCallback + }) + }); - assert.deepEqual(setCallback.args, [[ - newValue, - getValue, - { context: subject, key: 'computed', macro: 'key1' }, - { context: subject, key: 'computed', macro: alias('key2') } - ]]); -}); + subject.set('computed', newValue); -test('object syntax: preserves set value', function(assert) { - let { subject } = compute({ - computed: lazyComputed({ - get: getCallback, - set: setCallback - }) + assert.deepEqual(setCallback.args, [[ + newValue, + getValue, + { context: subject, key: 'computed', macro: 'key1' }, + { context: subject, key: 'computed', macro: alias('key2') } + ]]); }); - getCallback.reset(); + test('object syntax: preserves set value', function(assert) { + let { subject } = compute({ + computed: lazyComputed({ + get: getCallback, + set: setCallback + }) + }); - subject.set('computed', newValue); + getCallback.reset(); - assert.strictEqual(subject.get('computed'), setReturnValue); -}); + subject.set('computed', newValue); -test('function syntax: resolves array [] keys', function(assert) { - let { subject } = compute({ - computed: lazyComputed('key1.[]', getCallback) + assert.strictEqual(subject.get('computed'), setReturnValue); }); - assert.deepEqual(getCallback.args[0], [ - getValue, - { context: subject, key: 'computed', macro: 'key1' } - ]); -}); + test('function syntax: resolves array [] keys', function(assert) { + let { subject } = compute({ + computed: lazyComputed('key1.[]', getCallback) + }); -test('function syntax: resolves array @each keys', function(assert) { - let { subject } = compute({ - computed: lazyComputed('key1.@each.key2', getCallback) + assert.deepEqual(getCallback.args[0], [ + getValue, + { context: subject, key: 'computed', macro: 'key1' } + ]); }); - assert.deepEqual(getCallback.args[0], [ - getValue, - { context: subject, key: 'computed', macro: 'key1' } - ]); -}); + test('function syntax: resolves array @each keys', function(assert) { + let { subject } = compute({ + computed: lazyComputed('key1.@each.key2', getCallback) + }); -test('function syntax: expands properties', function(assert) { - let { subject } = compute({ - computed: lazyComputed('{key1,key2}', getCallback) + assert.deepEqual(getCallback.args[0], [ + getValue, + { context: subject, key: 'computed', macro: 'key1' } + ]); }); - assert.deepEqual(getCallback.args[0], [ - getValue, - { context: subject, key: 'computed', macro: 'key1' }, - { context: subject, key: 'computed', macro: 'key2' } - ]); -}); + test('function syntax: expands properties', function(assert) { + let { subject } = compute({ + computed: lazyComputed('{key1,key2}', getCallback) + }); -test('object syntax: resolves array [] keys', function(assert) { - let { subject } = compute({ - computed: lazyComputed('key1.[]', { - get: getCallback - }) + assert.deepEqual(getCallback.args[0], [ + getValue, + { context: subject, key: 'computed', macro: 'key1' }, + { context: subject, key: 'computed', macro: 'key2' } + ]); }); - assert.deepEqual(getCallback.args[0], [ - getValue, - { context: subject, key: 'computed', macro: 'key1' } - ]); -}); + test('object syntax: resolves array [] keys', function(assert) { + let { subject } = compute({ + computed: lazyComputed('key1.[]', { + get: getCallback + }) + }); -test('object syntax: resolves array @each keys', function(assert) { - let { subject } = compute({ - computed: lazyComputed('key1.@each.key2', { - get: getCallback - }) + assert.deepEqual(getCallback.args[0], [ + getValue, + { context: subject, key: 'computed', macro: 'key1' } + ]); }); - assert.deepEqual(getCallback.args[0], [ - getValue, - { context: subject, key: 'computed', macro: 'key1' } - ]); -}); + test('object syntax: resolves array @each keys', function(assert) { + let { subject } = compute({ + computed: lazyComputed('key1.@each.key2', { + get: getCallback + }) + }); -test('object syntax: expands properties', function(assert) { - let { subject } = compute({ - computed: lazyComputed('{key1,key2}', { - get: getCallback - }) + assert.deepEqual(getCallback.args[0], [ + getValue, + { context: subject, key: 'computed', macro: 'key1' } + ]); }); - assert.deepEqual(getCallback.args[0], [ - getValue, - { context: subject, key: 'computed', macro: 'key1' }, - { context: subject, key: 'computed', macro: 'key2' } - ]); + test('object syntax: expands properties', function(assert) { + let { subject } = compute({ + computed: lazyComputed('{key1,key2}', { + get: getCallback + }) + }); + + assert.deepEqual(getCallback.args[0], [ + getValue, + { context: subject, key: 'computed', macro: 'key1' }, + { context: subject, key: 'computed', macro: 'key2' } + ]); + }); }); diff --git a/tests/integration/literal-test.js b/tests/integration/literal-test.js index 2a79c9e..4a965ec 100644 --- a/tests/integration/literal-test.js +++ b/tests/integration/literal-test.js @@ -2,31 +2,31 @@ import literal from 'ember-macro-helpers/literal'; import { module, test } from 'qunit'; import compute from 'ember-macro-test-helpers/compute'; -module('Integration | literal'); - -test('it returns value verbatim', function(assert) { - compute({ - assert, - computed: literal('source'), - strictEqual: 'source' +module('Integration | literal', function() { + test('it returns value verbatim', function(assert) { + compute({ + assert, + computed: literal('source'), + strictEqual: 'source' + }); }); -}); -test('it doesn\'t treat it as a key, but as a string literal', function(assert) { - compute({ - assert, - computed: literal('source'), - properties: { - source: 'new source' - }, - strictEqual: 'source' + test('it doesn\'t treat it as a key, but as a string literal', function(assert) { + compute({ + assert, + computed: literal('source'), + properties: { + source: 'new source' + }, + strictEqual: 'source' + }); }); -}); -test('it is readOnly', function(assert) { - compute({ - assert, - computed: literal('source'), - assertReadOnly: true + test('it is readOnly', function(assert) { + compute({ + assert, + computed: literal('source'), + assertReadOnly: true + }); }); }); diff --git a/tests/integration/reads-test.js b/tests/integration/reads-test.js index b353139..77b68a5 100644 --- a/tests/integration/reads-test.js +++ b/tests/integration/reads-test.js @@ -11,199 +11,199 @@ const newValue = 'new value test'; let setCallback; -module('Integration | reads', { - beforeEach() { +module('Integration | reads', function(hooks) { + hooks.beforeEach(function() { setCallback = sinon.stub().returns(setReturnValue); - } -}); - -function alias(key) { - return computed(key, val => val); -} - -test('without setter: passes through the getter', function(assert) { - compute({ - assert, - computed: reads('key'), - properties: { - key: getReturnValue - }, - strictEqual: getReturnValue }); -}); -test('without setter: allows computed keys', function(assert) { - compute({ - assert, - computed: reads(raw(getReturnValue)), - strictEqual: getReturnValue + function alias(key) { + return computed(key, val => val); + } + + test('without setter: passes through the getter', function(assert) { + compute({ + assert, + computed: reads('key'), + properties: { + key: getReturnValue + }, + strictEqual: getReturnValue + }); }); -}); -test('without setter: allows setting', function(assert) { - let { subject } = compute({ - computed: reads(raw(getReturnValue)) + test('without setter: allows computed keys', function(assert) { + compute({ + assert, + computed: reads(raw(getReturnValue)), + strictEqual: getReturnValue + }); }); - subject.set('computed', newValue); + test('without setter: allows setting', function(assert) { + let { subject } = compute({ + computed: reads(raw(getReturnValue)) + }); - assert.strictEqual(subject.get('computed'), newValue); -}); + subject.set('computed', newValue); -test('without setter: is no longer a computed', function(assert) { - let { subject } = compute({ - computed: reads('key'), - properties: { - key: false - } + assert.strictEqual(subject.get('computed'), newValue); }); - subject.set('computed', false); - subject.set('key', true); + test('without setter: is no longer a computed', function(assert) { + let { subject } = compute({ + computed: reads('key'), + properties: { + key: false + } + }); - assert.strictEqual(subject.get('computed'), false); -}); + subject.set('computed', false); + subject.set('key', true); -test('with function setter: passes through the getter', function(assert) { - compute({ - assert, - computed: reads('key', setCallback), - properties: { - key: getReturnValue - }, - strictEqual: getReturnValue + assert.strictEqual(subject.get('computed'), false); }); -}); -test('with function setter: allows computed keys', function(assert) { - compute({ - assert, - computed: reads(raw(getReturnValue), setCallback), - strictEqual: getReturnValue + test('with function setter: passes through the getter', function(assert) { + compute({ + assert, + computed: reads('key', setCallback), + properties: { + key: getReturnValue + }, + strictEqual: getReturnValue + }); }); -}); -test('with function setter: `this` is object context', function(assert) { - let { subject } = compute({ - computed: reads(raw(getReturnValue), setCallback) + test('with function setter: allows computed keys', function(assert) { + compute({ + assert, + computed: reads(raw(getReturnValue), setCallback), + strictEqual: getReturnValue + }); }); - subject.set('computed', newValue); + test('with function setter: `this` is object context', function(assert) { + let { subject } = compute({ + computed: reads(raw(getReturnValue), setCallback) + }); - assert.strictEqual(setCallback.thisValues[0], subject); -}); + subject.set('computed', newValue); -test('with function setter: passes the value when setting', function(assert) { - let { subject } = compute({ - computed: reads(alias('key'), setCallback), - properties: { - key: '123' - } + assert.strictEqual(setCallback.thisValues[0], subject); }); - subject.set('computed', newValue); + test('with function setter: passes the value when setting', function(assert) { + let { subject } = compute({ + computed: reads(alias('key'), setCallback), + properties: { + key: '123' + } + }); - assert.deepEqual(setCallback.args, [[newValue, '123']]); -}); + subject.set('computed', newValue); -test('with function setter: setter return value is new value', function(assert) { - let { subject } = compute({ - computed: reads(raw(getReturnValue), setCallback) + assert.deepEqual(setCallback.args, [[newValue, '123']]); }); - subject.set('computed', newValue); + test('with function setter: setter return value is new value', function(assert) { + let { subject } = compute({ + computed: reads(raw(getReturnValue), setCallback) + }); - assert.strictEqual(subject.get('computed'), setReturnValue); -}); + subject.set('computed', newValue); -test('with function setter: is still a computed', function(assert) { - let { subject } = compute({ - computed: reads('key', setCallback), - properties: { - key: false - } + assert.strictEqual(subject.get('computed'), setReturnValue); }); - subject.set('computed', false); - subject.set('key', true); + test('with function setter: is still a computed', function(assert) { + let { subject } = compute({ + computed: reads('key', setCallback), + properties: { + key: false + } + }); - assert.strictEqual(subject.get('computed'), true); -}); + subject.set('computed', false); + subject.set('key', true); -test('with object setter: passes through the getter', function(assert) { - compute({ - assert, - computed: reads('key', { - set: setCallback - }), - properties: { - key: getReturnValue - }, - strictEqual: getReturnValue + assert.strictEqual(subject.get('computed'), true); }); -}); -test('with object setter: allows computed keys', function(assert) { - compute({ - assert, - computed: reads(raw(getReturnValue), { - set: setCallback - }), - strictEqual: getReturnValue + test('with object setter: passes through the getter', function(assert) { + compute({ + assert, + computed: reads('key', { + set: setCallback + }), + properties: { + key: getReturnValue + }, + strictEqual: getReturnValue + }); }); -}); -test('with object setter: `this` is object context', function(assert) { - let { subject } = compute({ - computed: reads(raw(getReturnValue), { - set: setCallback - }) + test('with object setter: allows computed keys', function(assert) { + compute({ + assert, + computed: reads(raw(getReturnValue), { + set: setCallback + }), + strictEqual: getReturnValue + }); }); - subject.set('computed', newValue); + test('with object setter: `this` is object context', function(assert) { + let { subject } = compute({ + computed: reads(raw(getReturnValue), { + set: setCallback + }) + }); - assert.strictEqual(setCallback.thisValues[0], subject); -}); + subject.set('computed', newValue); -test('with object setter: passes the value when setting', function(assert) { - let { subject } = compute({ - computed: reads(alias('key'), { - set: setCallback - }), - properties: { - key: '123' - } + assert.strictEqual(setCallback.thisValues[0], subject); }); - subject.set('computed', newValue); + test('with object setter: passes the value when setting', function(assert) { + let { subject } = compute({ + computed: reads(alias('key'), { + set: setCallback + }), + properties: { + key: '123' + } + }); - assert.deepEqual(setCallback.args, [[newValue, '123']]); -}); + subject.set('computed', newValue); -test('with object setter: setter return value is new value', function(assert) { - let { subject } = compute({ - computed: reads(raw(getReturnValue), { - set: setCallback - }) + assert.deepEqual(setCallback.args, [[newValue, '123']]); }); - subject.set('computed', newValue); + test('with object setter: setter return value is new value', function(assert) { + let { subject } = compute({ + computed: reads(raw(getReturnValue), { + set: setCallback + }) + }); - assert.strictEqual(subject.get('computed'), setReturnValue); -}); + subject.set('computed', newValue); -test('with object setter: is still a computed', function(assert) { - let { subject } = compute({ - computed: reads('key', { - set: setCallback - }), - properties: { - key: false - } + assert.strictEqual(subject.get('computed'), setReturnValue); }); - subject.set('computed', false); - subject.set('key', true); + test('with object setter: is still a computed', function(assert) { + let { subject } = compute({ + computed: reads('key', { + set: setCallback + }), + properties: { + key: false + } + }); - assert.strictEqual(subject.get('computed'), true); + subject.set('computed', false); + subject.set('key', true); + + assert.strictEqual(subject.get('computed'), true); + }); }); diff --git a/tests/unit/collapse-key-test.js b/tests/unit/collapse-key-test.js index 143e89b..2731a42 100644 --- a/tests/unit/collapse-key-test.js +++ b/tests/unit/collapse-key-test.js @@ -1,88 +1,88 @@ import collapseKey from 'ember-macro-helpers/collapse-key'; import { module, test } from 'qunit'; -module('Unit | collapse key'); +module('Unit | collapse key', function() { + test('it ignores non-strings', function(assert) { + assert.deepEqual( + collapseKey({}), + [{}] + ); + }); -test('it ignores non-strings', function(assert) { - assert.deepEqual( - collapseKey({}), - [{}] - ); -}); - -test('it collapses array.[]', function(assert) { - assert.deepEqual( - collapseKey('foo.[]'), - ['foo'] - ); -}); + test('it collapses array.[]', function(assert) { + assert.deepEqual( + collapseKey('foo.[]'), + ['foo'] + ); + }); -test('it collapses []', function(assert) { - assert.deepEqual( - collapseKey('[]'), - [''] - ); -}); + test('it collapses []', function(assert) { + assert.deepEqual( + collapseKey('[]'), + [''] + ); + }); -test('it collapses array.@each', function(assert) { - assert.deepEqual( - collapseKey('foo.@each.bar'), - ['foo'] - ); -}); + test('it collapses array.@each', function(assert) { + assert.deepEqual( + collapseKey('foo.@each.bar'), + ['foo'] + ); + }); -test('it collapses @each', function(assert) { - assert.deepEqual( - collapseKey('@each.bar'), - [''] - ); -}); + test('it collapses @each', function(assert) { + assert.deepEqual( + collapseKey('@each.bar'), + [''] + ); + }); -test('it collapses array.@each with brace expansion', function(assert) { - assert.deepEqual( - collapseKey('foo.@each.{bar,baz}'), - ['foo'] - ); -}); + test('it collapses array.@each with brace expansion', function(assert) { + assert.deepEqual( + collapseKey('foo.@each.{bar,baz}'), + ['foo'] + ); + }); -test('it collapses @each with brace expansion', function(assert) { - assert.deepEqual( - collapseKey('@each.{bar,baz}'), - [''] - ); -}); + test('it collapses @each with brace expansion', function(assert) { + assert.deepEqual( + collapseKey('@each.{bar,baz}'), + [''] + ); + }); -test('it ignores string without brace expansion', function(assert) { - assert.deepEqual( - collapseKey('foo'), - ['foo'] - ); -}); + test('it ignores string without brace expansion', function(assert) { + assert.deepEqual( + collapseKey('foo'), + ['foo'] + ); + }); -test('it collapses brace expansion', function(assert) { - assert.deepEqual( - collapseKey('foo.{bar,baz}'), - ['foo.bar', 'foo.baz'] - ); -}); + test('it collapses brace expansion', function(assert) { + assert.deepEqual( + collapseKey('foo.{bar,baz}'), + ['foo.bar', 'foo.baz'] + ); + }); -test('it collapses brace expansion with @each', function(assert) { - assert.deepEqual( - collapseKey('foo.{@each.bar,baz}'), - ['foo', 'foo.baz'] - ); -}); + test('it collapses brace expansion with @each', function(assert) { + assert.deepEqual( + collapseKey('foo.{@each.bar,baz}'), + ['foo', 'foo.baz'] + ); + }); -test('it collapses brace expansion with []', function(assert) { - assert.deepEqual( - collapseKey('foo.{bar.[],baz}'), - ['foo.bar', 'foo.baz'] - ); -}); + test('it collapses brace expansion with []', function(assert) { + assert.deepEqual( + collapseKey('foo.{bar.[],baz}'), + ['foo.bar', 'foo.baz'] + ); + }); -test('it collapses brace expansion with multiple array syntax', function(assert) { - assert.deepEqual( - collapseKey('foo.{bar.@each.foo,baz.[]}'), - ['foo.bar', 'foo.baz'] - ); + test('it collapses brace expansion with multiple array syntax', function(assert) { + assert.deepEqual( + collapseKey('foo.{bar.@each.foo,baz.[]}'), + ['foo.bar', 'foo.baz'] + ); + }); }); diff --git a/tests/unit/collapse-keys-test.js b/tests/unit/collapse-keys-test.js index 18638c8..e703b73 100644 --- a/tests/unit/collapse-keys-test.js +++ b/tests/unit/collapse-keys-test.js @@ -1,102 +1,102 @@ import collapseKeys, { collapseKeysWithMap } from 'ember-macro-helpers/collapse-keys'; import { module, test } from 'qunit'; -module('Unit | collapse keys'); +module('Unit | collapse keys', function() { + test('it allows empty arrays', function(assert) { + assert.deepEqual( + collapseKeys([]), + [] + ); + }); -test('it allows empty arrays', function(assert) { - assert.deepEqual( - collapseKeys([]), - [] - ); -}); + test('it ignores non-strings', function(assert) { + assert.deepEqual( + collapseKeys([{}]), + [{}] + ); + }); -test('it ignores non-strings', function(assert) { - assert.deepEqual( - collapseKeys([{}]), - [{}] - ); -}); + test('it collapses array.[]', function(assert) { + assert.deepEqual( + collapseKeys(['foo.[]']), + ['foo'] + ); + }); -test('it collapses array.[]', function(assert) { - assert.deepEqual( - collapseKeys(['foo.[]']), - ['foo'] - ); -}); + test('it collapses array.@each', function(assert) { + assert.deepEqual( + collapseKeys(['foo.@each.bar']), + ['foo'] + ); + }); -test('it collapses array.@each', function(assert) { - assert.deepEqual( - collapseKeys(['foo.@each.bar']), - ['foo'] - ); -}); + test('it collapses array.@each with brace expansion', function(assert) { + assert.deepEqual( + collapseKeys(['foo.@each.{bar,baz}']), + ['foo'] + ); + }); -test('it collapses array.@each with brace expansion', function(assert) { - assert.deepEqual( - collapseKeys(['foo.@each.{bar,baz}']), - ['foo'] - ); -}); - -test('it ignores string without brace expansion', function(assert) { - assert.deepEqual( - collapseKeys(['foo', 'one']), - ['foo', 'one'] - ); -}); + test('it ignores string without brace expansion', function(assert) { + assert.deepEqual( + collapseKeys(['foo', 'one']), + ['foo', 'one'] + ); + }); -test('it collapses brace expansion', function(assert) { - assert.deepEqual( - collapseKeys(['foo.{bar,baz}', 'one.{two,three}']), - ['foo.bar', 'foo.baz', 'one.two', 'one.three'] - ); -}); + test('it collapses brace expansion', function(assert) { + assert.deepEqual( + collapseKeys(['foo.{bar,baz}', 'one.{two,three}']), + ['foo.bar', 'foo.baz', 'one.two', 'one.three'] + ); + }); -test('keyMap: it allows empty arrays', function(assert) { - assert.deepEqual( - collapseKeysWithMap([]).keyMap, - [] - ); -}); + test('keyMap: it allows empty arrays', function(assert) { + assert.deepEqual( + collapseKeysWithMap([]).keyMap, + [] + ); + }); -test('keyMap: it ignores non-strings', function(assert) { - assert.deepEqual( - collapseKeysWithMap([{}]).keyMap, - [0] - ); -}); + test('keyMap: it ignores non-strings', function(assert) { + assert.deepEqual( + collapseKeysWithMap([{}]).keyMap, + [0] + ); + }); -test('keyMap: it ignores array.[]', function(assert) { - assert.deepEqual( - collapseKeysWithMap(['foo.[]']).keyMap, - [0] - ); -}); + test('keyMap: it ignores array.[]', function(assert) { + assert.deepEqual( + collapseKeysWithMap(['foo.[]']).keyMap, + [0] + ); + }); -test('keyMap: it ignores array.@each', function(assert) { - assert.deepEqual( - collapseKeysWithMap(['foo.@each.bar']).keyMap, - [0] - ); -}); + test('keyMap: it ignores array.@each', function(assert) { + assert.deepEqual( + collapseKeysWithMap(['foo.@each.bar']).keyMap, + [0] + ); + }); -test('keyMap: it ignores array.@each with brace expansion', function(assert) { - assert.deepEqual( - collapseKeysWithMap(['foo.@each.{bar,baz}']).keyMap, - [0] - ); -}); + test('keyMap: it ignores array.@each with brace expansion', function(assert) { + assert.deepEqual( + collapseKeysWithMap(['foo.@each.{bar,baz}']).keyMap, + [0] + ); + }); -test('keyMap: it ignores string without brace expansion', function(assert) { - assert.deepEqual( - collapseKeysWithMap(['foo', 'one']).keyMap, - [0, 1] - ); -}); + test('keyMap: it ignores string without brace expansion', function(assert) { + assert.deepEqual( + collapseKeysWithMap(['foo', 'one']).keyMap, + [0, 1] + ); + }); -test('keyMap: it collapses brace expansion', function(assert) { - assert.deepEqual( - collapseKeysWithMap(['foo.{bar,baz}', 'one.{two,three}']).keyMap, - [0, 0, 1, 1] - ); + test('keyMap: it collapses brace expansion', function(assert) { + assert.deepEqual( + collapseKeysWithMap(['foo.{bar,baz}', 'one.{two,three}']).keyMap, + [0, 0, 1, 1] + ); + }); }); diff --git a/tests/unit/controllers/dummy-test.js b/tests/unit/controllers/dummy-test.js index 667ace2..7fdd020 100644 --- a/tests/unit/controllers/dummy-test.js +++ b/tests/unit/controllers/dummy-test.js @@ -1,28 +1,29 @@ import { run } from '@ember/runloop'; -import { moduleFor, test } from 'ember-qunit'; +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; let store; -moduleFor('controller:dummy', 'Unit | Controller | dummy', { - needs: ['model:parent', 'model:child'], +module('Unit | Controller | dummy', function(hooks) { + setupTest(hooks); - beforeEach() { - store = this.container.lookup('service:store'); - } -}); + hooks.beforeEach(function() { + store = this.owner.lookup('service:store'); + }); -test('it doesn\'t have detroyed errors when working with controllers + async model relationships', function(assert) { - let model = run(() => { - return store.createRecord('parent', { - children: [ - store.createRecord('child', { name: 'foo' }), - store.createRecord('child', { name: 'bar' }) - ] + test('it doesn\'t have detroyed errors when working with controllers + async model relationships', function(assert) { + let model = run(() => { + return store.createRecord('parent', { + children: [ + store.createRecord('child', { name: 'foo' }), + store.createRecord('child', { name: 'bar' }) + ] + }); }); - }); - let controller = this.subject({ model }); + let controller = this.owner.factoryFor('controller:dummy').create({ model }); - let result = controller.get('childNames'); + let result = controller.get('childNames'); - assert.deepEqual(result, ['foo', 'bar']); + assert.deepEqual(result, ['foo', 'bar']); + }); }); diff --git a/tests/unit/create-class-computed-test.js b/tests/unit/create-class-computed-test.js index d08f88f..96dbca7 100644 --- a/tests/unit/create-class-computed-test.js +++ b/tests/unit/create-class-computed-test.js @@ -9,180 +9,180 @@ import destroy from '../helpers/destroy'; let callback; -module('Unit | create class computed', { - beforeEach() { +module('Unit | create class computed', function(hooks) { + hooks.beforeEach(function() { callback = sinon.stub().returns('test return value'); - } -}); - -test('it returns the callback response', function(assert) { - let macro = createClassComputed( - [], - () => computed(callback) - ); - - compute({ - assert, - computed: macro(), - strictEqual: 'test return value' }); -}); -test('it initially calculates correctly', function(assert) { - let macro = createClassComputed( - [false], - test1 => computed(test1, callback) - ); - - compute({ - computed: macro('test2'), - properties: { - test2: 'test3' - } + test('it returns the callback response', function(assert) { + let macro = createClassComputed( + [], + () => computed(callback) + ); + + compute({ + assert, + computed: macro(), + strictEqual: 'test return value' + }); }); - assert.deepEqual(callback.args, [ - [undefined], - ['test3'] - ]); -}); + test('it initially calculates correctly', function(assert) { + let macro = createClassComputed( + [false], + test1 => computed(test1, callback) + ); + + compute({ + computed: macro('test2'), + properties: { + test2: 'test3' + } + }); + + assert.deepEqual(callback.args, [ + [undefined], + ['test3'] + ]); + }); -test('it still works when you leave off optional observers', function(assert) { - let macro = createClassComputed( - [], - test1 => computed(test1, callback) - ); - - compute({ - computed: macro('test2'), - properties: { - test2: 'test3' - } + test('it still works when you leave off optional observers', function(assert) { + let macro = createClassComputed( + [], + test1 => computed(test1, callback) + ); + + compute({ + computed: macro('test2'), + properties: { + test2: 'test3' + } + }); + + assert.deepEqual(callback.args, [ + [undefined], + ['test3'] + ]); }); - assert.deepEqual(callback.args, [ - [undefined], - ['test3'] - ]); -}); + test('it responds to array changes internally', function(assert) { + let array = emberA([ + EmberObject.create({ test2: 1 }), + EmberObject.create({ test2: 1 }) + ]); -test('it responds to array changes internally', function(assert) { - let array = emberA([ - EmberObject.create({ test2: 1 }), - EmberObject.create({ test2: 1 }) - ]); - - let macro = createClassComputed( - [false], - test1 => computed(`${test1}.@each.test2`, callback) - ); - - let { subject } = compute({ - computed: macro('test3'), - properties: { - test3: array - } - }); + let macro = createClassComputed( + [false], + test1 => computed(`${test1}.@each.test2`, callback) + ); - array.set('1.test2', 2); + let { subject } = compute({ + computed: macro('test3'), + properties: { + test3: array + } + }); - subject.get('computed'); + array.set('1.test2', 2); - assert.equal(callback.callCount, 3); - assert.deepEqual(emberA(callback.lastCall.args[0]).mapBy('test2'), [1, 2]); -}); + subject.get('computed'); -test('it responds to array changes externally', function(assert) { - let array = emberA([ - EmberObject.create({ test2: 1 }), - EmberObject.create({ test2: 1 }) - ]); - - let macro = createClassComputed( - [false], - test1 => computed(test1, callback) - ); - - let { subject } = compute({ - computed: macro('test3.@each.test2'), - properties: { - test3: array - } + assert.equal(callback.callCount, 3); + assert.deepEqual(emberA(callback.lastCall.args[0]).mapBy('test2'), [1, 2]); }); - array.set('1.test2', 2); + test('it responds to array changes externally', function(assert) { + let array = emberA([ + EmberObject.create({ test2: 1 }), + EmberObject.create({ test2: 1 }) + ]); - subject.get('computed'); + let macro = createClassComputed( + [false], + test1 => computed(test1, callback) + ); - assert.equal(callback.callCount, 3); - assert.deepEqual(emberA(callback.lastCall.args[0]).mapBy('test2'), [1, 2]); -}); + let { subject } = compute({ + computed: macro('test3.@each.test2'), + properties: { + test3: array + } + }); -test('it rewrites when observer changes', function(assert) { - let array = emberA([ - EmberObject.create({ test2: 1, test6: 2 }), - EmberObject.create({ test2: 1, test6: 2 }) - ]); - - let observerCallback = sinon.spy( - (test1, test4) => computed(`${test1}.@each.${test4}`, callback) - ); - - let macro = createClassComputed( - [false, true], - observerCallback - ); - - let { subject } = compute({ - computed: macro('test3', 'test5'), - properties: { - test3: array, - test5: 'test2' - } + array.set('1.test2', 2); + + subject.get('computed'); + + assert.equal(callback.callCount, 3); + assert.deepEqual(emberA(callback.lastCall.args[0]).mapBy('test2'), [1, 2]); }); - assert.equal(observerCallback.callCount, 2); + test('it rewrites when observer changes', function(assert) { + let array = emberA([ + EmberObject.create({ test2: 1, test6: 2 }), + EmberObject.create({ test2: 1, test6: 2 }) + ]); - assert.equal(callback.callCount, 2); + let observerCallback = sinon.spy( + (test1, test4) => computed(`${test1}.@each.${test4}`, callback) + ); - subject.set('test5', 'test6'); + let macro = createClassComputed( + [false, true], + observerCallback + ); - assert.equal(observerCallback.callCount, 3); + let { subject } = compute({ + computed: macro('test3', 'test5'), + properties: { + test3: array, + test5: 'test2' + } + }); - subject.get('computed'); + assert.equal(observerCallback.callCount, 2); - assert.equal(callback.callCount, 3); + assert.equal(callback.callCount, 2); - array.set('1.test6', 3); + subject.set('test5', 'test6'); - subject.get('computed'); + assert.equal(observerCallback.callCount, 3); - assert.equal(observerCallback.callCount, 3); + subject.get('computed'); - assert.equal(callback.callCount, 4); -}); + assert.equal(callback.callCount, 3); -test('it cleans up after destroy', function(assert) { - let array = emberA([ - EmberObject.create({ test2: 1 }), - EmberObject.create({ test2: 1 }) - ]); - - let macro = createClassComputed( - [false], - test1 => computed(`${test1}.@each.test2`, callback) - ); - - let { subject } = compute({ - computed: macro('test3'), - properties: { - test3: array - } - }); + array.set('1.test6', 3); - destroy(subject, () => { - array.set('1.test2', 2); + subject.get('computed'); - assert.equal(callback.callCount, 2); + assert.equal(observerCallback.callCount, 3); + + assert.equal(callback.callCount, 4); + }); + + test('it cleans up after destroy', function(assert) { + let array = emberA([ + EmberObject.create({ test2: 1 }), + EmberObject.create({ test2: 1 }) + ]); + + let macro = createClassComputed( + [false], + test1 => computed(`${test1}.@each.test2`, callback) + ); + + let { subject } = compute({ + computed: macro('test3'), + properties: { + test3: array + } + }); + + destroy(subject, () => { + array.set('1.test2', 2); + + assert.equal(callback.callCount, 2); + }); }); }); diff --git a/tests/unit/expand-property-list-test.js b/tests/unit/expand-property-list-test.js index 85d5b75..ec52193 100644 --- a/tests/unit/expand-property-list-test.js +++ b/tests/unit/expand-property-list-test.js @@ -1,40 +1,40 @@ import expandPropertyList from 'ember-macro-helpers/expand-property-list'; import { module, test } from 'qunit'; -module('Unit | expand property list'); +module('Unit | expand property list', function() { + test('it passes through a key', function(assert) { + let result = expandPropertyList(['key']); -test('it passes through a key', function(assert) { - let result = expandPropertyList(['key']); + assert.deepEqual(result, ['key']); + }); - assert.deepEqual(result, ['key']); -}); - -test('it retains any dots', function(assert) { - let result = expandPropertyList(['key1.key2']); + test('it retains any dots', function(assert) { + let result = expandPropertyList(['key1.key2']); - assert.deepEqual(result, ['key1.key2']); -}); + assert.deepEqual(result, ['key1.key2']); + }); -test('it retains array []', function(assert) { - let result = expandPropertyList(['key1.key2.[]']); + test('it retains array []', function(assert) { + let result = expandPropertyList(['key1.key2.[]']); - assert.deepEqual(result, ['key1.key2.[]']); -}); + assert.deepEqual(result, ['key1.key2.[]']); + }); -test('it retains array @each', function(assert) { - let result = expandPropertyList(['key1.@each.key2']); + test('it retains array @each', function(assert) { + let result = expandPropertyList(['key1.@each.key2']); - assert.deepEqual(result, ['key1.@each.key2']); -}); + assert.deepEqual(result, ['key1.@each.key2']); + }); -test('it expands properties', function(assert) { - let result = expandPropertyList(['key1.{key2,key3}']); + test('it expands properties', function(assert) { + let result = expandPropertyList(['key1.{key2,key3}']); - assert.deepEqual(result, ['key1.key2', 'key1.key3']); -}); + assert.deepEqual(result, ['key1.key2', 'key1.key3']); + }); -test('it expands array properties', function(assert) { - let result = expandPropertyList(['key1.@each.{key2,key3}']); + test('it expands array properties', function(assert) { + let result = expandPropertyList(['key1.@each.{key2,key3}']); - assert.deepEqual(result, ['key1.@each.key2', 'key1.@each.key3']); + assert.deepEqual(result, ['key1.@each.key2', 'key1.@each.key3']); + }); }); diff --git a/tests/unit/expand-property-test.js b/tests/unit/expand-property-test.js index f590676..fd62026 100644 --- a/tests/unit/expand-property-test.js +++ b/tests/unit/expand-property-test.js @@ -1,40 +1,40 @@ import expandProperty from 'ember-macro-helpers/expand-property'; import { module, test } from 'qunit'; -module('Unit | expand property'); +module('Unit | expand property', function() { + test('it passes through a key', function(assert) { + let result = expandProperty('key'); -test('it passes through a key', function(assert) { - let result = expandProperty('key'); + assert.deepEqual(result, ['key']); + }); - assert.deepEqual(result, ['key']); -}); - -test('it retains any dots', function(assert) { - let result = expandProperty('key1.key2'); + test('it retains any dots', function(assert) { + let result = expandProperty('key1.key2'); - assert.deepEqual(result, ['key1.key2']); -}); + assert.deepEqual(result, ['key1.key2']); + }); -test('it retains array []', function(assert) { - let result = expandProperty('key1.key2.[]'); + test('it retains array []', function(assert) { + let result = expandProperty('key1.key2.[]'); - assert.deepEqual(result, ['key1.key2.[]']); -}); + assert.deepEqual(result, ['key1.key2.[]']); + }); -test('it retains array @each', function(assert) { - let result = expandProperty('key1.@each.key2'); + test('it retains array @each', function(assert) { + let result = expandProperty('key1.@each.key2'); - assert.deepEqual(result, ['key1.@each.key2']); -}); + assert.deepEqual(result, ['key1.@each.key2']); + }); -test('it expands properties', function(assert) { - let result = expandProperty('key1.{key2,key3}'); + test('it expands properties', function(assert) { + let result = expandProperty('key1.{key2,key3}'); - assert.deepEqual(result, ['key1.key2', 'key1.key3']); -}); + assert.deepEqual(result, ['key1.key2', 'key1.key3']); + }); -test('it expands array properties', function(assert) { - let result = expandProperty('key1.@each.{key2,key3}'); + test('it expands array properties', function(assert) { + let result = expandProperty('key1.@each.{key2,key3}'); - assert.deepEqual(result, ['key1.@each.key2', 'key1.@each.key3']); + assert.deepEqual(result, ['key1.@each.key2', 'key1.@each.key3']); + }); }); diff --git a/tests/unit/flatten-keys-test.js b/tests/unit/flatten-keys-test.js index b42fdea..1552c9f 100644 --- a/tests/unit/flatten-keys-test.js +++ b/tests/unit/flatten-keys-test.js @@ -4,58 +4,58 @@ import { module } from 'qunit'; import computed from 'ember-macro-helpers/computed'; import namedTest from '../helpers/named-test'; -module('Unit | flatten keys'); - -function dummyMacro(...args) { - args.push(() => {}); - return computed(...args); -} - -[ - { - name: 'flattenKeys', - flattenKeys - }, - { - name: 'flattenKeysUnsafe', - flattenKeys: flattenKeysUnsafe - } -].forEach(({ name, flattenKeys }) => { - function test(title, callback) { - namedTest(name, title, callback); +module('Unit | flatten keys', function() { + function dummyMacro(...args) { + args.push(() => {}); + return computed(...args); } - test('it works', function(assert) { - let key1 = 'test1'; - let key2 = dummyMacro('test2', dummyMacro('test3', 'test4')); + [ + { + name: 'flattenKeys', + flattenKeys + }, + { + name: 'flattenKeysUnsafe', + flattenKeys: flattenKeysUnsafe + } + ].forEach(({ name, flattenKeys }) => { + function test(title, callback) { + namedTest(name, title, callback); + } + + test('it works', function(assert) { + let key1 = 'test1'; + let key2 = dummyMacro('test2', dummyMacro('test3', 'test4')); + + let flattenedKeys = flattenKeys([key1, key2]); + + assert.deepEqual(flattenedKeys, [ + 'test1', + 'test2', + 'test3', + 'test4' + ]); + }); + + test('it handles undefined _dependentKeys (raw)', function(assert) { + let key = dummyMacro(); + + let flattenedKeys = flattenKeys([key]); + + assert.deepEqual(flattenedKeys, []); + }); + }); - let flattenedKeys = flattenKeys([key1, key2]); + namedTest('flattenKeys', 'it retains keys with spaces', function(assert) { + let flattenedKeys = flattenKeys(['string with spaces']); - assert.deepEqual(flattenedKeys, [ - 'test1', - 'test2', - 'test3', - 'test4' - ]); + assert.deepEqual(flattenedKeys, ['string with spaces']); }); - test('it handles undefined _dependentKeys (raw)', function(assert) { - let key = dummyMacro(); - - let flattenedKeys = flattenKeys([key]); + namedTest('flattenKeysUnsafe', 'it removes keys with spaces', function(assert) { + let flattenedKeys = flattenKeysUnsafe(['string with spaces']); assert.deepEqual(flattenedKeys, []); }); }); - -namedTest('flattenKeys', 'it retains keys with spaces', function(assert) { - let flattenedKeys = flattenKeys(['string with spaces']); - - assert.deepEqual(flattenedKeys, ['string with spaces']); -}); - -namedTest('flattenKeysUnsafe', 'it removes keys with spaces', function(assert) { - let flattenedKeys = flattenKeysUnsafe(['string with spaces']); - - assert.deepEqual(flattenedKeys, []); -}); diff --git a/tests/unit/get-value-test.js b/tests/unit/get-value-test.js index c134253..8b000aa 100644 --- a/tests/unit/get-value-test.js +++ b/tests/unit/get-value-test.js @@ -5,96 +5,96 @@ import { module } from 'qunit'; import sinon from 'sinon'; import namedTest from '../helpers/named-test'; -module('Unit | get value'); - -[ - { - name: 'getValue', - getValue - }, - { - name: 'getValueUnsafe', - getValue: getValueUnsafe - } -].forEach(({ name, getValue }) => { - function test(title, callback) { - namedTest(name, title, callback); - } - - test('it returns undefined if no params', function(assert) { - let value = getValue(); +module('Unit | get value', function() { + [ + { + name: 'getValue', + getValue + }, + { + name: 'getValueUnsafe', + getValue: getValueUnsafe + } + ].forEach(({ name, getValue }) => { + function test(title, callback) { + namedTest(name, title, callback); + } - assert.strictEqual(value, undefined); - }); + test('it returns undefined if no params', function(assert) { + let value = getValue(); - test('it returns undefined if undefined', function(assert) { - let value = getValue(undefined); + assert.strictEqual(value, undefined); + }); - assert.strictEqual(value, undefined); - }); + test('it returns undefined if undefined', function(assert) { + let value = getValue(undefined); - test('it returns undefined if empty object', function(assert) { - let value = getValue({}); + assert.strictEqual(value, undefined); + }); - assert.strictEqual(value, undefined); - }); + test('it returns undefined if empty object', function(assert) { + let value = getValue({}); - test('it evaluates regular properties', function(assert) { - let context = { - testKey: 'test value' - }; + assert.strictEqual(value, undefined); + }); - let value = getValue({ context, macro: 'testKey' }); + test('it evaluates regular properties', function(assert) { + let context = { + testKey: 'test value' + }; - assert.strictEqual(value, 'test value'); - }); + let value = getValue({ context, macro: 'testKey' }); - test('it evaluates computed properties', function(assert) { - let context = {}; - let callback = sinon.stub().returns('test value'); - let macro = computed(callback); - let key = 'computedName'; + assert.strictEqual(value, 'test value'); + }); - let value = getValue({ context, macro, key }); + test('it evaluates computed properties', function(assert) { + let context = {}; + let callback = sinon.stub().returns('test value'); + let macro = computed(callback); + let key = 'computedName'; - assert.strictEqual(callback.thisValues[0], context); - assert.deepEqual(callback.args[0], [key]); - assert.strictEqual(value, 'test value'); - }); + let value = getValue({ context, macro, key }); - test('calulates false value consistently', function(assert) { - let context = { - testKey: false - }; + assert.strictEqual(callback.thisValues[0], context); + assert.deepEqual(callback.args[0], [key]); + assert.strictEqual(value, 'test value'); + }); - let value = getValue({ context, macro: 'testKey' }); + test('calulates false value consistently', function(assert) { + let context = { + testKey: false + }; - assert.strictEqual(value, false); - }); + let value = getValue({ context, macro: 'testKey' }); + + assert.strictEqual(value, false); + }); - test('returns the context if the macro is blank', function(assert) { - let context = { - testKey: 'test value' - }; + test('returns the context if the macro is blank', function(assert) { + let context = { + testKey: 'test value' + }; - let value = getValue({ context, macro: '' }); + let value = getValue({ context, macro: '' }); - assert.strictEqual(value, context); + assert.strictEqual(value, context); + }); }); -}); -namedTest('getValue', 'returns undefined if property doesn\'t exist', function(assert) { - let context = {}; + namedTest('getValue', 'returns undefined if property doesn\'t exist', function(assert) { + let context = {}; - let value = getValue({ context, macro: 'testKey' }); + let value = getValue({ context, macro: 'testKey' }); - assert.strictEqual(value, undefined); -}); + assert.strictEqual(value, undefined); + }); -namedTest('getValueUnsafe', 'returns literal if property doesn\'t exist', function(assert) { - let context = {}; + namedTest('getValueUnsafe', 'returns literal if property doesn\'t exist', function(assert) { + let context = {}; - let value = getValueUnsafe({ context, macro: 'testKey' }); + let value = getValueUnsafe({ context, macro: 'testKey' }); - assert.strictEqual(value, 'testKey'); + assert.strictEqual(value, 'testKey'); + }); }); diff --git a/tests/unit/is-computed-test.js b/tests/unit/is-computed-test.js index 1187db7..a4e87dd 100644 --- a/tests/unit/is-computed-test.js +++ b/tests/unit/is-computed-test.js @@ -2,34 +2,34 @@ import { computed } from '@ember/object'; import isComputed from 'ember-macro-helpers/is-computed'; import { module, test } from 'qunit'; -module('Unit | is computed'); +module('Unit | is computed', function() { + test('it returns true for computed', function(assert) { + let result = isComputed(computed(() => {})); -test('it returns true for computed', function(assert) { - let result = isComputed(computed(() => {})); + assert.strictEqual(result, true); + }); - assert.strictEqual(result, true); -}); + test('it returns false for object', function(assert) { + let result = isComputed({}); -test('it returns false for object', function(assert) { - let result = isComputed({}); + assert.strictEqual(result, false); + }); - assert.strictEqual(result, false); -}); + test('it returns false for string', function(assert) { + let result = isComputed(''); -test('it returns false for string', function(assert) { - let result = isComputed(''); + assert.strictEqual(result, false); + }); - assert.strictEqual(result, false); -}); + test('it returns false for number', function(assert) { + let result = isComputed(0); -test('it returns false for number', function(assert) { - let result = isComputed(0); - - assert.strictEqual(result, false); -}); + assert.strictEqual(result, false); + }); -test('it returns false for boolean', function(assert) { - let result = isComputed(false); + test('it returns false for boolean', function(assert) { + let result = isComputed(false); - assert.strictEqual(result, false); + assert.strictEqual(result, false); + }); }); diff --git a/tests/unit/normalize-array-key-test.js b/tests/unit/normalize-array-key-test.js index 347fcb8..ee476f3 100644 --- a/tests/unit/normalize-array-key-test.js +++ b/tests/unit/normalize-array-key-test.js @@ -1,124 +1,124 @@ import normalizeArrayKey from 'ember-macro-helpers/normalize-array-key'; import { module, test } from 'qunit'; -module('Unit | normalize array key'); +module('Unit | normalize array key', function() { + test('it wraps array if string', function(assert) { + let result = normalizeArrayKey('foo.bar'); -test('it wraps array if string', function(assert) { - let result = normalizeArrayKey('foo.bar'); + assert.strictEqual(result, 'foo.bar.[]'); + }); - assert.strictEqual(result, 'foo.bar.[]'); -}); + test('it wraps array if string and empty keys', function(assert) { + let result = normalizeArrayKey('foo.bar', []); -test('it wraps array if string and empty keys', function(assert) { - let result = normalizeArrayKey('foo.bar', []); + assert.strictEqual(result, 'foo.bar.[]'); + }); - assert.strictEqual(result, 'foo.bar.[]'); -}); + test('it ignores undefined keys', function(assert) { + let result = normalizeArrayKey('foo.bar', [undefined]); -test('it ignores undefined keys', function(assert) { - let result = normalizeArrayKey('foo.bar', [undefined]); + assert.strictEqual(result, 'foo.bar.[]'); + }); - assert.strictEqual(result, 'foo.bar.[]'); -}); + test('it does nothing for non-string', function(assert) { + let obj = {}; -test('it does nothing for non-string', function(assert) { - let obj = {}; + let result = normalizeArrayKey(obj); - let result = normalizeArrayKey(obj); + assert.strictEqual(result, obj); + }); - assert.strictEqual(result, obj); -}); + test('it does nothing for non-string and empty keys', function(assert) { + let obj = {}; -test('it does nothing for non-string and empty keys', function(assert) { - let obj = {}; + let result = normalizeArrayKey(obj, []); - let result = normalizeArrayKey(obj, []); + assert.strictEqual(result, obj); + }); - assert.strictEqual(result, obj); -}); + test('it does nothing for non-string and keys', function(assert) { + let obj = {}; -test('it does nothing for non-string and keys', function(assert) { - let obj = {}; + let result = normalizeArrayKey(obj, ['prop']); - let result = normalizeArrayKey(obj, ['prop']); + assert.strictEqual(result, obj); + }); - assert.strictEqual(result, obj); -}); + test('it does not alter array.[]', function(assert) { + let result = normalizeArrayKey('foo.bar.[]'); -test('it does not alter array.[]', function(assert) { - let result = normalizeArrayKey('foo.bar.[]'); + assert.strictEqual(result, 'foo.bar.[]'); + }); - assert.strictEqual(result, 'foo.bar.[]'); -}); + test('it does not alter array.[] with empty keys', function(assert) { + let result = normalizeArrayKey('foo.bar.[]', []); -test('it does not alter array.[] with empty keys', function(assert) { - let result = normalizeArrayKey('foo.bar.[]', []); + assert.strictEqual(result, 'foo.bar.[]'); + }); - assert.strictEqual(result, 'foo.bar.[]'); -}); + test('it does not alter []', function(assert) { + let result = normalizeArrayKey('[]'); -test('it does not alter []', function(assert) { - let result = normalizeArrayKey('[]'); + assert.strictEqual(result, '[]'); + }); - assert.strictEqual(result, '[]'); -}); + test('it does not alter [] with empty keys', function(assert) { + let result = normalizeArrayKey('[]', []); -test('it does not alter [] with empty keys', function(assert) { - let result = normalizeArrayKey('[]', []); + assert.strictEqual(result, '[]'); + }); - assert.strictEqual(result, '[]'); -}); + test('it does not alter array.@each.prop', function(assert) { + let result = normalizeArrayKey('foo.bar.@each.prop'); -test('it does not alter array.@each.prop', function(assert) { - let result = normalizeArrayKey('foo.bar.@each.prop'); + assert.strictEqual(result, 'foo.bar.@each.prop'); + }); - assert.strictEqual(result, 'foo.bar.@each.prop'); -}); + test('it does not alter array.@each.prop with empty keys', function(assert) { + let result = normalizeArrayKey('foo.bar.@each.prop', []); -test('it does not alter array.@each.prop with empty keys', function(assert) { - let result = normalizeArrayKey('foo.bar.@each.prop', []); + assert.strictEqual(result, 'foo.bar.@each.prop'); + }); - assert.strictEqual(result, 'foo.bar.@each.prop'); -}); + test('it does not alter @each.prop', function(assert) { + let result = normalizeArrayKey('@each.prop'); -test('it does not alter @each.prop', function(assert) { - let result = normalizeArrayKey('@each.prop'); + assert.strictEqual(result, '@each.prop'); + }); - assert.strictEqual(result, '@each.prop'); -}); + test('it does not alter @each.prop with empty keys', function(assert) { + let result = normalizeArrayKey('@each.prop', []); -test('it does not alter @each.prop with empty keys', function(assert) { - let result = normalizeArrayKey('@each.prop', []); + assert.strictEqual(result, '@each.prop'); + }); - assert.strictEqual(result, '@each.prop'); -}); + test('it watches array prop when raw array', function(assert) { + let result = normalizeArrayKey('foo.bar', ['prop']); -test('it watches array prop when raw array', function(assert) { - let result = normalizeArrayKey('foo.bar', ['prop']); + assert.strictEqual(result, 'foo.bar.@each.prop'); + }); - assert.strictEqual(result, 'foo.bar.@each.prop'); -}); + test('it watches array prop when already watching array length', function(assert) { + let result = normalizeArrayKey('foo.bar.[]', ['prop']); -test('it watches array prop when already watching array length', function(assert) { - let result = normalizeArrayKey('foo.bar.[]', ['prop']); + assert.strictEqual(result, 'foo.bar.@each.prop'); + }); - assert.strictEqual(result, 'foo.bar.@each.prop'); -}); - -test('it watches multiple array props when already watching array length', function(assert) { - let result = normalizeArrayKey('foo.bar.[]', ['prop', 'prop2']); + test('it watches multiple array props when already watching array length', function(assert) { + let result = normalizeArrayKey('foo.bar.[]', ['prop', 'prop2']); - assert.strictEqual(result, 'foo.bar.@each.{prop,prop2}'); -}); + assert.strictEqual(result, 'foo.bar.@each.{prop,prop2}'); + }); -test('it watches array prop when already watching array prop', function(assert) { - let result = normalizeArrayKey('foo.bar.@each.baz', ['prop']); + test('it watches array prop when already watching array prop', function(assert) { + let result = normalizeArrayKey('foo.bar.@each.baz', ['prop']); - assert.strictEqual(result, 'foo.bar.@each.{baz,prop}'); -}); + assert.strictEqual(result, 'foo.bar.@each.{baz,prop}'); + }); -test('it watches multiple array props when already watching multiple array props', function(assert) { - let result = normalizeArrayKey('foo.bar.@each.{baz,baz2}', ['prop', 'prop2']); + test('it watches multiple array props when already watching multiple array props', function(assert) { + let result = normalizeArrayKey('foo.bar.@each.{baz,baz2}', ['prop', 'prop2']); - assert.strictEqual(result, 'foo.bar.@each.{baz,baz2,prop,prop2}'); + assert.strictEqual(result, 'foo.bar.@each.{baz,baz2,prop,prop2}'); + }); });