You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to run this test in cacheable.decorator.spec.ts
[...]
@Cacheable()
getDataWithParamObj(parameter: any) {
return this.mockServiceCall(parameter);
}
[...]
it("return the cached observable with params object", () => {
let params = {
limit: 5,
stars: ["1"],
page: 1,
q: ""
};
/**
* call the service endpoint five hundred times with the same parameter
* but the service should only be called once, since the observable will be cached
*/
for (let i = 0; i < 500; i++) {
service.getDataWithParamObj(params);
}
expect(mockServiceCallSpy).toHaveBeenCalledTimes(1);
/**
* return the response
*/
jasmine.clock().tick(1000);
params.stars.push("2");
/**
* call again..
*/
service.getDataWithParamObj(params);
/**
* service call count should still be 1, since we are returning from cache now
*/
expect(mockServiceCallSpy).toHaveBeenCalledTimes(2);
});
[...]
Wouldn't it miss a clone of the parameters before saving them as old parameters. or something like that ?
Thank you for your help 🙂
UPDATE :
If you add cloneDeep of the parameters before the call to the "cacheable observable" it corrects the problem. But I still think it's up to the lib to do the job 🙂
If I find what I need to modify in the library, I will propose a PR 😉
The text was updated successfully, but these errors were encountered:
Yeah that makes sense, since you are passing a referential type, the stringify comparison that's done later will always return true. Can you make a PR about that and I will merge it and re-publish as soon as I can :) Thanks!
Hi,
I would like to run this test in
cacheable.decorator.spec.ts
Wouldn't it miss a clone of the parameters before saving them as old parameters. or something like that ?
Thank you for your help 🙂
UPDATE :
If you add cloneDeep of the parameters before the call to the "cacheable observable" it corrects the problem. But I still think it's up to the lib to do the job 🙂
If I find what I need to modify in the library, I will propose a PR 😉
The text was updated successfully, but these errors were encountered: