Skip to content

Commit

Permalink
test(includes): add includes function tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hamilton committed Jul 2, 2019
1 parent 2596d53 commit dae23a8
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/__tests__/includes.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import includes from '../includes';

describe('includes', () => {
test('should return true or false whether or not the object has the specified value', () => {
const obj = {
a: 1,
b: 2,
};

expect(includes(obj, 1)).toBe(true);
expect(includes(obj, 2)).toBe(true);
expect(includes(obj, 3)).toBe(false);
});

test('should check within deep objects with follow is true', () => {
const obj = {
a: 1,
b: {
c: {
d: 2,
},
},
};

expect(includes(obj, 2)).toBe(false);
expect(includes(obj, 2, {
follow: true,
})).toBe(true);
});

test('should throw TypeError for invalid arguments', () => {
const invalidObj: unknown = 'testing';
const invalidFollow: unknown = 'testing';

expect(() => includes(invalidObj as OObject, 'test'))
.toThrow(new TypeError('Expected Object, got string testing'));
expect(() => includes({}, 'test', {
follow: invalidFollow as boolean,
}))
.toThrow(new TypeError('Expected Boolean, got string testing'));
});
});

0 comments on commit dae23a8

Please # to comment.