nestjs
nestjs copied to clipboard
Primitive Property Caching on DeepMocked Objects
I am not sure if this is intended or not, and I did not see an issue already filed regarding this so I am filing it here.
nodejs: v18 @golevelup/ts-jest: 0.3.5
Given the following:
class A {
someProperty: boolean
}
const mockedObjectA: DeepMocked<A> = createMock<A>({ someProperty: true });
If I am doing the test and run the following, it would be okay
expect(mockedObjectA.someProperty).toBeTrue(); // this is okay
If I do this, it seems to be okay too:
mockedObjectA.someProperty = false; // assignment before accessing the value seems to be okay
expect(mockedObjectA.someProperty).toBeFalse(); // this is okay
If I do this after accessing the property first, then the property is locked into its original value:
expect(mockedObjectA.someProperty).toBeTrue(); // assertion okay
mockedObjectA.someProperty = false;
expect(mockedObjectA.someProperty).toBeFalse(); // this fails - instead of false, it is true here
Please comment.
@kchow1985 Hi, sorry for getting back at this so late. This seems to a bug of some sort, might require an investigation but if you're willing to help and contribute a fix it would be appreciated as i don't have that much free time to dig in