Skip to content

Commit

Permalink
add set test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelly Selden committed Dec 26, 2016
1 parent 588caac commit 32c78e4
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions tests/integration/computed-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import sinon from 'sinon';
import compute from 'ember-macro-test-helpers/compute';
import namedTest from '../helpers/named-test';

const returnValue = 'return value test';
const getReturnValue = 'get return value test';
const setReturnValue = 'set return value test';
const newValue = 'new value test';

let getCallback;
let setCallback;

module('Integration | Utility | computed', {
beforeEach() {
getCallback = sinon.stub().returns(returnValue);
setCallback = sinon.stub();
getCallback = sinon.stub().returns(getReturnValue);
setCallback = sinon.stub().returns(setReturnValue);
}
});

Expand All @@ -40,15 +41,15 @@ function alias(key) {
compute({
assert,
computed: computed(getCallback),
strictEqual: returnValue
strictEqual: getReturnValue
});
});

test('works with undefined key', function(assert) {
compute({
assert,
computed: computed('key1', getCallback),
strictEqual: returnValue
strictEqual: getReturnValue
});
});

Expand Down Expand Up @@ -151,7 +152,22 @@ function alias(key) {

subject.set('computed', newValue);

assert.deepEqual(setCallback.args, [['computed', newValue, returnValue]]);
assert.deepEqual(setCallback.args, [['computed', newValue, getReturnValue]]);
});

test('object syntax: preserves set value', function(assert) {
let { subject } = compute({
computed: computed({
get: getCallback,
set: setCallback
})
});

getCallback.reset();

subject.set('computed', newValue);

assert.strictEqual(subject.get('computed'), setReturnValue);
});
});

Expand Down

0 comments on commit 32c78e4

Please sign in to comment.