Questions tagged [jest-fetch-mock]

99 questions
0
votes
1 answer

Next.js jest-fetch-mock gives error of TextDecoder

I have the following setup for my Next.JS jest.config.js /* eslint-disable @typescript-eslint/no-var-requires */ // jest.config.js const nextJest = require('next/jest') const createJestConfig = nextJest({ // Provide the path to your Next.js app…
rottitime
  • 1,653
  • 17
  • 29
0
votes
0 answers

Javascript testing: Mocking dispatch and get state

The test should be checking if inbox.get is getting called with current user id 12345 for currentuser filter criteria. When I run the tests, it's not able to enter return(dispatch, getstate), out of the two console logs that i added here only…
0
votes
1 answer

dependency injection for creating knex instance enabling db access to be mocked in tests

Looking for typescript sample code for creating knex database instance through dependency injection. Goal is to mock knex in unit testing and not hardwiring knex instance in the DAO files for data acccess
Rajeev
  • 1
  • 1
0
votes
1 answer

Vue Jest Framework | Uncovered lines are show as invalid

I am using jest framework for vue.js unit test cases. My issue is my file lines of code is 31. But showing uncovered line is 39, 40. Is there any issue in config related things. What is the issue here. I am facing this issue in all my .vue files.…
0
votes
0 answers

Jest Mock issues with async functions with .then

i have the follow code async function searchCharacter(){ const response = await fetch("https://rickandmortyapi.com/api/character/?name=") .then((response) => { if(response.status !== 200) throw `HTTP error: ${response.status}`; …
KeyGy
  • 35
  • 5
0
votes
1 answer

How to define describe(), it() and expect() in a vue.js using jest & eslint?

How to define describe(), it() and expect() in this Case ?? am getting the : No files found in C:\Users\tarek\Dogalu\dogalu_frontend_v2. Make sure Jest's configuration does not exclude this directory. To set up Jest, make sure a package.json file…
law kira
  • 73
  • 4
0
votes
1 answer

Testing Redux Toolkit Query using jest issue with auth

Im currently trying to write jest test for my RTKQuery, but I get stuck on the authentication level for the test. Basically the api Im using is designed to have the token on query param instead of having it on the request header:…
user14459580
  • 206
  • 2
  • 12
0
votes
0 answers

how to test the fetch post request using jest

How to mock the fetch statement using jest export default function Login() { function LoginUser() { const requestOptions = { method: 'POST', headers: { 'Content-Type': 'application/json', Accept:…
0
votes
0 answers

How to test function arg to be number with Jest

How can I test if a function arg it's a number? I got a simple function of leap year, so I'd like to test if the user inputs a number (not string nor boolean) in "year" argument. const isLeapYear = (year) => ((year % 100 === 0) ? (year % 400 === 0)…
Kelson Batista
  • 406
  • 4
  • 25
0
votes
0 answers

Jest tests randomly failing while running all tests together

Jest tests are created to check node js end points. But while running tests together some tests are randomly failing and getting following error. Those tests is working fine while running indually. Request failed with status code 500 at…
0
votes
1 answer

Jest test failing with two errors

This is the test I'm trying to run: it('should return Notification Groups', (done) => { fetchAppNotifications('123', 'abc').subscribe((response) => { try { expect(response).toEqual(MOCK_FETCH_APP_NOTIFICATIONS_RESPONSE); done(); …
mycroft16
  • 785
  • 10
  • 28
0
votes
1 answer

Callback response in Jest is different than normal response

I have a method that calls an endpoint in React Native and I want to test it with jest. Everything is asynchronous and it works but the callback response when the function is called in testing side is totally different than the response when the…
poPaTheGuru
  • 1,009
  • 1
  • 13
  • 35
0
votes
1 answer

Mock .get() Function using Jest on VueJS

I am trying to mock a GET request to get some Posts using the ID. This is the code I am trying to mock: getPost() { this.refreshToken(); http .get(`/posts/${this.$cookie.get('postid')}`, { headers: { "Authorization": `Bearer…
ckyzm
  • 1
  • 1
0
votes
1 answer

React and Typescript - Tests are failing due to type error "Conversion of type 'Global & typeof globalThis' to type 'GlobalWithFetchMock'..."

Working with React and Typescript is fantastic, but can sometimes result in head-scratching issues. In this case all my test failed with the same error related to jest-fetch-mock: > NODE_ENV=test jest FAIL src/store/index.test.tsx ● Test suite…
Anas
  • 1,345
  • 14
  • 15
0
votes
0 answers

How do I make a Jest test to check that a post is being rendered correctly in VueJS?

I'm trying to test that a GET request is working correctly for Jest, and I can fetch posts by their ID. Please bear with me, I'm very new to front-end testing and not fully sure about how to go about this. This is my GET request: getPost() { …
ckyzm
  • 1
  • 1