Skip to content

Commit 65230d3

Browse files
author
Seth Davenport
committed
unit tests tor tassign
1 parent 6a604e3 commit 65230d3

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/utils/shallow-equal.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,10 @@ describe('Utils', () => {
5353
)
5454
).to.equal(false);
5555
});
56+
57+
it('should return true for two references to the same thing', () => {
58+
const thing = { a: 1, b: 2, c: undefined };
59+
expect(shallowEqual(thing, thing)).to.equal(true);
60+
});
5661
});
5762
});

src/utils/tassign.spec.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { expect } from 'chai';
2+
import { tassign } from './tassign';
3+
4+
describe('tassign', () => {
5+
it('Returns an object with original and new values', () => {
6+
const initial = {
7+
a: 1,
8+
b: 2,
9+
};
10+
11+
const assigned = {
12+
b: 3,
13+
};
14+
15+
const expected = {
16+
a: 1,
17+
b: 3,
18+
};
19+
20+
expect(tassign(initial, assigned)).to.eql(expected);
21+
});
22+
23+
it('Returns a new object reference', () => {
24+
const initial = {
25+
a: 1,
26+
b: 2,
27+
};
28+
29+
const assigned = {};
30+
31+
expect(tassign(initial, assigned)).not.to.equal(initial);
32+
});
33+
34+
it('Does not mutate the original object', () => {
35+
const initial = {
36+
a: 1,
37+
b: 2,
38+
};
39+
40+
const assigned = {
41+
b: 3,
42+
};
43+
44+
const expected = {
45+
a: 1,
46+
b: 2,
47+
};
48+
49+
tassign(initial, assigned);
50+
expect(initial).to.eql(expected);
51+
});
52+
});

0 commit comments

Comments
 (0)