Skip to content

Commit

Permalink
Update object check to include instance
Browse files Browse the repository at this point in the history
  • Loading branch information
poteto committed Mar 5, 2016
1 parent 9961a51 commit 7e807af
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
7 changes: 7 additions & 0 deletions addon/utils/is-object.js
@@ -0,0 +1,7 @@
import Ember from 'ember';

const { typeOf } = Ember;

export default function isObject(val) {
return typeOf(val) === 'object' || typeOf(val) === 'instance';
}
3 changes: 2 additions & 1 deletion addon/utils/is-promise.js
@@ -1,4 +1,5 @@
import Ember from 'ember';
import isObject from './is-object';

const { typeOf } = Ember;

Expand All @@ -9,5 +10,5 @@ function isPromiseLike(obj = {}) {
}

export default function isPromise(obj) {
return typeOf(obj) === 'object' && isPromiseLike(obj);
return isObject(obj) && isPromiseLike(obj);
}
34 changes: 34 additions & 0 deletions tests/unit/utils/is-object-test.js
@@ -0,0 +1,34 @@
import Ember from 'ember';
import isObject from 'ember-composable-helpers/utils/is-object';
import { module, test } from 'qunit';

const { Object: EmberObject, ObjectProxy } = Ember;

module('Unit | Utility | is object');

let testData = [
{
label: 'POJOs',
value: { foo: 'bar' },
expected: true
},
{
label: 'EmberObjects',
value: EmberObject.create({ foo: 'bar' }),
expected: true
},
{
label: 'ObjectProxies',
value: ObjectProxy.create({
content: EmberObject.create({ foo: 'bar' })
}),
expected: true
}
];

testData.forEach(({ label, value, expected }) => {
test(`it works with ${label}`, function(assert) {
let result = isObject(value);
assert.equal(result, expected, `should be ${expected}`);
});
});

0 comments on commit 7e807af

Please sign in to comment.