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 want to setup some custom utils for our jest testing environment, since Apollos MockedProvider isn't sufficient enough.
My goal is to have some generated mock data if needed, but also to have the possibility, to add custom mocks.
Surfing through forums I've found following blog, which some of you could already be familiar with: https://www.arahansen.com/testing-apollo-components-using-react-testing-library/
The idea is clear to me. I just need to get it working with custom Scalars. It's almost running, but I seem to be missing some information or have overseen something in the graphql-tool docs perhaps.
I started by generating a GraphQL schema out of an introspection file and made it useable by using graphql-tools makeExecutableSchema. So far so good.
However trying get addMocksToSchema running as intended, I'm facing some issues.
import{screen}from"@testing-library/react";import{render}from"utils/test-utils/render";importComponentToTestfrom"./component-to-test";it("should render the temperature current value",async()=>{render(<ComponentToTestid="someGuid"/>,// id gets passed to query, to get a specific item{mock: {TemperatureControlType: {temperatureValue: {currentValue: "20",},id: "someGuid"},},},);awaitscreen.findByText("20");});
Adding those fields to the test with some dummy data, doesn't solve the issue. Same console errors are still being displayed.
I guess I get something wrong with my addMocksToSchema. The mocking is somehow working, since "Hello World" is part of the console error, though I wonder why even in the test my custom mocked currentValue: "20" is being replaced by "Hello World" and anyway none of my custom mocks are working.
Would be glad if someone could help me out, since I'm trying getting my tests running for some days now. I think I can make it work with graphql-tools, I'm just missing some little detail I guess..
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I want to setup some custom utils for our jest testing environment, since Apollos MockedProvider isn't sufficient enough.
My goal is to have some generated mock data if needed, but also to have the possibility, to add custom mocks.
Surfing through forums I've found following blog, which some of you could already be familiar with:
https://www.arahansen.com/testing-apollo-components-using-react-testing-library/
The idea is clear to me. I just need to get it working with custom Scalars. It's almost running, but I seem to be missing some information or have overseen something in the graphql-tool docs perhaps.
I started by generating a GraphQL schema out of an introspection file and made it useable by using graphql-tools makeExecutableSchema. So far so good.
However trying get addMocksToSchema running as intended, I'm facing some issues.
With my schema looking something like:
my custom render function:
and my test looking something like this:
I get some console errors looking like:
or
basically for every field I haven't mocked.
Adding those fields to the test with some dummy data, doesn't solve the issue. Same console errors are still being displayed.
I guess I get something wrong with my addMocksToSchema. The mocking is somehow working, since "Hello World" is part of the console error, though I wonder why even in the test my custom mocked
currentValue: "20"
is being replaced by "Hello World" and anyway none of my custom mocks are working.Would be glad if someone could help me out, since I'm trying getting my tests running for some days now. I think I can make it work with graphql-tools, I'm just missing some little detail I guess..
Beta Was this translation helpful? Give feedback.
All reactions