Closed
Description
this happens with both cloneDeep and compat.cloneDeep.
It is then affecting other functions like omit
.
it('should work with custom classes', () => {
class CustomTest {
constructor(public value: number) {}
myFunc() {
return `value is ${this.value}`;
}
}
const object = new CustomTest(1);
const cloned = cloneDeep(object);
expect(cloned).not.toBe(object);
expect(cloned).toEqual(object);
expect(cloned.myFunc()).toBe(object.myFunc()); // <- Error: TypeError: cloned.myFunc is not a function
expect(cloned.myFunc()).toEqual('value is 1');
const nested = { customTest: new CustomTest(1) };
const clonedNested = cloneDeep(nested);
expect(clonedNested).not.toBe(nested);
expect(clonedNested).toEqual(nested);
expect(clonedNested.customTest.myFunc()).toBe(nested.customTest.myFunc());
expect(clonedNested.customTest.myFunc()).toEqual('value is 1');
});
Metadata
Metadata
Assignees
Labels
No labels