[RESTDataSource] Unable to run tests with Jest
See original GitHub issueWhenever I’m trying to run a test using a class that extends RESTDataSource and call the this.get(...)
method, I have the following error TypeError: Cannot read property 'fetch' of undefined
The thing is I want to test the real output of the request, so mocking the fetch method doesn’t seems to be an appropriate solution.
Some related files are: https://github.com/apollographql/apollo-server/blob/master/__mocks__/apollo-server-env.ts https://github.com/apollographql/apollo-server/blob/master/packages/apollo-datasource-rest/src/HTTPCache.ts#L11
How can I get ride of this error ? Is there any example that could show me how test a rest data source ?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Jest test fials with error "DataSource is not set for this entity"
The issue appears in tests made with jest and I got the following error: "DataSource is not set for this entity". Am i...
Read more >How to write tests for Prisma with Docker and Jest
src/prisma/schema.prisma datasource db { provider = "mysql" url ... We can't run tests unless we write a function to test first .
Read more >Jest CLI Options
Run tests related to changed files based on hg/git (uncommitted files): ... Exit the test suite immediately upon n number of failing test...
Read more >apollo-datasource-rest - npm
This package exports a ([`RESTDataSource`](https://github.com/ ... Start using apollo-datasource-rest in your project by running `npm i ...
Read more >please make sure that the argument datasource at index [0] is ...
mockResolvedValue(mockContact), find: jest.fn(). ... when i run the test,fail with Nest can't resolve dependencies of the OrderService (?).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@melkir try to call it like
I had the same issue. This line makes it compile with no typescript warnings:
But if you need a real cache to fix
[TypeError: this.keyValueCache.get is not a function
, use