Skip to content
This repository has been archived by the owner on Jun 26, 2021. It is now read-only.

Commit

Permalink
add pojo support. closes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelcobain committed Feb 10, 2016
1 parent fdea398 commit a75de6b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
4 changes: 2 additions & 2 deletions addon/helpers/toggle.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Ember from 'ember';

const { Helper: { helper } } = Ember;
const { Helper: { helper }, get, set } = Ember;

export function toggle([obj, prop]) {
return function() {
obj.toggleProperty(prop);
set(obj, prop, !get(obj, prop));
};
}

Expand Down
32 changes: 31 additions & 1 deletion tests/unit/helpers/toggle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,35 @@ test('it toggles the property', function(assert) {
let action = toggle([jimBob, 'isAlive']);
action();

assert.ok(get(jimBob, 'isAlive'), 'it toggles the property');
assert.ok(get(jimBob, 'isAlive') === true, 'it toggles the property');
});

test('it toggles the property of a POJO', function(assert) {
let jimBob = {
isAlive: false
};
let action = toggle([jimBob, 'isAlive']);
action();

assert.ok(get(jimBob, 'isAlive') === true, 'it toggles the property of a POJO');
});

test('it correctly toggles non-boolean falsy values', function(assert) {
let jimBob = {
isAlive: undefined
};
let action = toggle([jimBob, 'isAlive']);
action();

assert.ok(get(jimBob, 'isAlive') === true, 'it toggles the property of a POJO');
});

test('it correctly toggles non-boolean truthy values', function(assert) {
let jimBob = {
isAlive: {}
};
let action = toggle([jimBob, 'isAlive']);
action();

assert.ok(get(jimBob, 'isAlive') === false, 'it toggles the property of a POJO');
});

0 comments on commit a75de6b

Please sign in to comment.