add plain object check and omit helpers
This commit is contained in:
48
test/src/helpers/is_plain_object.js
Normal file
48
test/src/helpers/is_plain_object.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import expect from 'expect.js';
|
||||
import isPlainObject from '../../../lib/helpers/is_plain_object';
|
||||
|
||||
function validateItems(checks, pass) {
|
||||
checks.forEach(check => {
|
||||
expect(isPlainObject(check)).to.be(pass);
|
||||
});
|
||||
}
|
||||
|
||||
describe('isPlainObject', function () {
|
||||
describe('non-object primitives', function () {
|
||||
it('return false', function () {
|
||||
const checks = [
|
||||
100,
|
||||
true,
|
||||
'i am a string',
|
||||
function noop() {},
|
||||
null,
|
||||
];
|
||||
|
||||
validateItems(checks, false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('arrays', function () {
|
||||
it('return false', function () {
|
||||
const checks = [
|
||||
[],
|
||||
[1,2,3],
|
||||
['just a string'],
|
||||
];
|
||||
|
||||
validateItems(checks, false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('', function () {
|
||||
it('return true', function () {
|
||||
const checks = [
|
||||
{},
|
||||
{one:1},
|
||||
{object:{with:{array:[]}}},
|
||||
];
|
||||
|
||||
validateItems(checks, true);
|
||||
});
|
||||
});
|
||||
});
|
||||
37
test/src/helpers/omit.js
Normal file
37
test/src/helpers/omit.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import expect from 'expect.js';
|
||||
import objectOmit from '../../../lib/helpers/object_omit';
|
||||
|
||||
describe('object omit', function () {
|
||||
let obj = {};
|
||||
|
||||
beforeEach(() => {
|
||||
obj = {
|
||||
one: 1,
|
||||
two: 2,
|
||||
three: 3,
|
||||
arr: [1,2,3],
|
||||
check: 'aw yeah',
|
||||
};
|
||||
});
|
||||
|
||||
it('omits a single property', function () {
|
||||
const val = objectOmit(obj, 'one');
|
||||
|
||||
expect(val).to.eql({
|
||||
two: 2,
|
||||
three: 3,
|
||||
arr: [1,2,3],
|
||||
check: 'aw yeah',
|
||||
});
|
||||
});
|
||||
|
||||
it('omits multiple properties', function () {
|
||||
const val = objectOmit(obj, ['three', 'check']);
|
||||
|
||||
expect(val).to.eql({
|
||||
one: 1,
|
||||
two: 2,
|
||||
arr: [1,2,3],
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user