damlReact.useQuery is not working for test cases
- priyankaOP 1
Hi Team,
We have recently upgraded our Daml version from 1.6.0 to 1.16.0.
UseQuery is working fine functionality wise but we see some issue with our test cases.
I am just giving structure of one test case where we are trying to use damlReact.useQueryFor eg -
damlReact.useQuery = jest.fn((template: any, argument, dependency) => {
return { loading: false, contracts: [] }; });We get below error -
TypeError: Cannot set property useQuery of [object Object] which has only a getterCould you please help us to resolve this issue.
Thanks,
Priyanka - cocreature 1
Hi @priyanka, this looks like you’re probably running into reactjs - TypeError during Jest's spyOn: Cannot set property getRequest of #<Object> which has only a getter - Stack Overflow or something very similar to that.
I’m not super familiar with jest but it looks like the most robust solution is to mock
@daml/reactcompletely rather than trying to override individual functions.We do something similar in our own tests for mocking
@daml/ledgerdaml/index.test.ts at 1b23f91a92ee937b67673dd60d592f2bc98d9ac0 · digital-asset/daml · GitHub - priyanka 1
Thanks for your reply.
Yes, issue was to related to mocking. I mocked data differently and it worked for me.