mockDeep nested object issue
jpasquers opened this issue · comments
Joseph Pasque commented
I created a repository showcasing this:
https://github.com/jpasquers/jest-mock-extended-fail-example
The important part being the following
import { mockDeep } from "jest-mock-extended";
interface X {
y: {
[a: string]: string
}
z: {
z1: string;
}
}
describe('nested mock', () => {
it('should be empty inner object', () => {
let mock = mockDeep<X>({y: {}});
//This fails -> Received: [Function mockConstructor]
expect(mock.y["something"]).toBeUndefined();
})
})
Since I am providing an implementation of y that is {}
shouldn't mock.y["something"]
be undefined?
Austin Dworaczyk Wiltshire commented
Just ran into this surprise as well.
Edit - using undefined
instead of an empty object literal {}
ended up working for me:
mockDeep<X>({y: undefined});