Skip to content

Commit

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

describe('set', () => {
test('should return a new object not a reference', () => {
const obj = {};
const result = set(obj, 'a', 1);

expect(result.a).toBe(1);
expect(Object.keys(obj)).toHaveLength(0);
});

test('should set the specified value on the object', () => {
const obj = {};
const result = set(obj, 'a', 1);

expect(result.a).toBe(1);
});

test('should use dot notation for the path', () => {
const obj = {};
const result = set(obj, 'a.b', 1);

expect(result.a.b).toBe(1);
});

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

expect(() => set(invalidObj as OObject, 'test', 'test'))
.toThrow(new TypeError('Expected Object, got string testing'));
expect(() => set({}, invalidPath as string, 'test'))
.toThrow(new TypeError('Expected String, got number 1'));
});
});

0 comments on commit 5a00ac1

Please # to comment.