1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
import {
is,
isImmutable,
isValueObject,
List,
Map,
Set,
Stack,
} from 'immutable';
describe('isImmutable', () => {
it('behaves as advertised', () => {
expect(isImmutable([])).toBe(false);
expect(isImmutable({})).toBe(false);
expect(isImmutable(Map())).toBe(true);
expect(isImmutable(List())).toBe(true);
expect(isImmutable(Set())).toBe(true);
expect(isImmutable(Stack())).toBe(true);
expect(isImmutable(Map().asMutable())).toBe(true);
});
});
describe('isValueObject', () => {
it('behaves as advertised', () => {
expect(isValueObject(null)).toBe(false);
expect(isValueObject(123)).toBe(false);
expect(isValueObject('abc')).toBe(false);
expect(isValueObject([])).toBe(false);
expect(isValueObject({})).toBe(false);
expect(isValueObject(Map())).toBe(true);
expect(isValueObject(List())).toBe(true);
expect(isValueObject(Set())).toBe(true);
expect(isValueObject(Stack())).toBe(true);
expect(isValueObject(Map().asMutable())).toBe(true);
});
it('works on custom types', () => {
class MyValueType {
v: any;
constructor(val) {
this.v = val;
}
equals(other) {
return Boolean(other && this.v === other.v);
}
hashCode() {
return this.v;
}
}
expect(isValueObject(new MyValueType(123))).toBe(true);
expect(is(new MyValueType(123), new MyValueType(123))).toBe(true);
expect(Set().add(new MyValueType(123)).add(new MyValueType(123)).size).toBe(
1
);
});
});
|