cy.mockGraphql is not a function - reactjs

Trying to run a test using cypress-graphql-mock in Next.js project but getting this error: cy.mockGraphql is not a function
Both cypress and cypress-graphql-mock are installed.
In the description of the library it says: "Adds commands for executing a mocked GraphQL server using only the client", But I have no idea why it is not adding a function.

Op was able to solve it by adding import "cypress-graphql-mock"; into the support/command.js file.

Related

Observing error while running Gatling project 'object gatling is not a member of package io'

I m seeing the following error while running Engine.scala
object gatling is not a member of package io import io.gatling.app.Gatling
Below is the code that is used
`import io.gatling.app.Gatling
import io.gatling.core.config.GatlingPropertiesBuilder
object Engine extends App {
val props = new GatlingPropertiesBuilder()
.resourcesDirectory(IDEPathHelper.mavenResourcesDirectory.toString)
.resultsDirectory(IDEPathHelper.resultsDirectory.toString)
.binariesDirectory(IDEPathHelper.mavenBinariesDirectory.toString)
Gatling.fromMap(props.build)
}`
I tried changing the Gatling version in mvn file, but no luck. could someone please help
It means the Gatling jars are not properly imported in your classpath.
No idea how to help you though as you're not describing exactly what you're doing and how you're getting this error: when running maven from the command line? when running from IntelliJ? or another IDE?
Note: if you're struggling with properly setting up a development environment for Scala, you should probably consider using Gatling with Java instead, where the set up is way more simple.

Connect front-end to Alchemy using alchemy-web3 in nextjs

So I'm trying to connect my react front-end to an alchemy node using alchemy-web3 as it says in this tutorial from the official website:
https://docs.alchemy.com/docs/integrating-your-smart-contract-with-the-frontend
The problem comes when I create that interact.js file and gives me an error saying:
TypeError: Cannot set property Request of # which has only a getter
I've seen other questions with this same error but using web3 library. In my case, I'm using that other library, alchemy-web3 (even if it's a wrapper of Web3) in a Nextjs. Do you know how to fix this problem, or if you know any documentation to connect a front-end with an alchemy node but maybe using web3 in a Nextjs app? That is important, in a Nextjs.

jest.mock - Cannot find module in React test file

I want to mock broadcast-channel in my test case and was following the jest documentation on how to mock a module. However when I run the test, I get an error 'Cannot find module 'BroadcastChannel' from 'broadcast.test.js''
I tried looking at the githubs of both jest and broadcast-channel for similar issues but nothing came up.
Inside broadcast.test.js
import BroadcastChannel from 'broadcast-channel';
jest.mock('BroadcastChannel');
It should run the test case using the mock broadcast-channel. However, I only get the error:
'Cannot find module 'BroadcastChannel' from 'broadcast.test.js''
You can set up a setupTests file, where you can create a manual mock for the BroadcastChannel and set it for the window.
if (!window.BroadcastChannel) window.BroadcastChannel = BroadcastChannelMock;
This applies when you use react-scripts test for running tests.

How to get the GraphQL schema in TypeScript

I have a React project that uses TypeScript and GraphQL using apollo.
I have a global Type file that has all the required files. It is generated from the schema.json file , by running apollo-codegen
The steps I follow are:
Run the GraphiQL
Copy the response of POST request to graphQL
Paste it in the schema.json file
Create the graphQL query ( .graphql file )
Run apollo-codegen
Is there a better way to do this programatically ?
I'm not sure what part of the code to share along with this question.
You can use gql2ts and then run $ gql2ts schema.json
I have had great success with the following project: https://graphql-code-generator.com/
Works amazing across your graphql server and client implementation.

Yarn test failing - Network request failed

I created a react project using create-react-app however when ran yarn test to see if the initial tests pass I get
TypeError: Network request failed
at XMLHttpRequest.xhr.onerror (/home/ubuntu/wonderland/hackernews/node_modules/whatwg-fetch/fetch.js:436:16)
at XMLHttpRequest.callback.(anonymous function) (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:289:32)
at invokeEventListeners (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:219:27)
at invokeInlineListeners (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:166:7)
at EventTargetImpl._dispatch (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:122:7)
at EventTargetImpl.dispatchEvent (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:87:17)
at XMLHttpRequest.dispatchEvent (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:61:35)
at XMLHttpRequest.abort (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:405:16)
at Object.abort (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:315:13)
at RequestManager.close (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:146:21)
at Window.close (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/browser/Window.js:362:29)
at JSDOMEnvironment.dispose (/home/ubuntu/wonderland/hackernews/node_modules/jest-environment-jsdom/build/index.js:44:19)
at Promise.resolve.then (/home/ubuntu/wonderland/hackernews/node_modules/jest-cli/build/runTest.js:102:17)
I'm working in Cloud9 editor using ssh connected to my dev server (Ubuntu) hosted in AWS. Tests are working fine in my local machine (Ubuntu).
Thanks for the help!
I already solve my problem. I'm following a book entitled "The Road to Learn React" and I think that the one causing my error is the part where I fetch data from an external API. The book forgot to include an import for fetch which is this one:
import fetch from 'isomorphic-fetch'
Then, it solves my problem like a charm.

Resources