jestjs Questions

4

Solved

I have read many of the questions similar to mine, but none seem to fix my issue. I am using Vue3, TypeScript, Jest, and D3 v7. When I try to import * as d3 from "d3"; I get this error in...
Spiculum asked 17/9, 2021 at 16:27

6

Solved

I'm building a React app, with create-react-app. I got the following error when running ESLint: 8:3 error 'document' is not defined no-undef. My app runs without error, but I got this ESLint erro...
Purgatory asked 21/2, 2017 at 20:12

1

I have the following files in a React app with Vitest (which has the same API as Jest): // hooks/useEntities/useEntities.ts return useEntities() { // this hooks send api requests so I will mock i...
Cesar asked 15/12, 2022 at 15:46

7

Solved

I'm working with VSCode and installed the extension: "Jest" for better jest-testing-enviroment. In the extension's instruction I saw we get a nice intellisense support for Jest's commands. The Pr...
Erudite asked 20/2, 2018 at 14:18

4

Solved

I want to verify that a mocked API is called with an object which does not contain a specific field. expect(api.method).toBeCalledWith(expectedObject); Since the actual parameters of the api.met...
Brush asked 14/3, 2019 at 10:16

3

Solved

I'm trying to write a unit test for the logic within Vue's mounted() lifecycle hook, but not having much luck. The problem seems to be that mounted() never gets called when the component is mounted...
Custodian asked 10/5, 2018 at 17:49

8

I have an API that does not omit JSON serialization for fields with "empty" (null, none, nil) values and returns all of them as "fieldName": null. I have typed DTOs in testing c...
Ketose asked 15/5, 2020 at 4:38

2

I'm new at typescript. My Nestjs project app is something like this. I'm trying to use repository pattern, so i separated business logic (service) and persistance logic (repository) UserRepository...
Amaranth asked 12/3, 2020 at 10:54

3

Solved

I'm learning testing on react and react components with react testing library and jest. While trying to test a component that works when rendering the component it works with no issue, but when tes...
Lauretta asked 28/1, 2023 at 20:29

5

Solved

I got a custom hook which I want to test. It receives a redux store dispatch function and returns a function. In order to get the result I'm trying to do: const { result } = renderHook(() => { ...
Dionedionis asked 25/12, 2019 at 9:21

3

I'm trying to mock one of Typeorm module function in Jest and I want to do it in cleanest possible way. What I managed to create that works: jest.mock("typeorm", () => ({ __esModule: ...
Hufuf asked 12/5, 2021 at 19:18

6

I have spent a long time looking at other questions about this and looking at other projects on Github but none of the answers seem to work for me. I am loading a third party library in my project...
Kingsley asked 3/5, 2018 at 5:59

6

I want to use jest for my server unit testing (instead of mocha+chai). Is there a way I can run async function before all tests start (init purposes) only once and not for every test file? And also...
Sloan asked 26/7, 2017 at 0:53

3

🙂 I'm learning testing in React, but fireEvent doesn't change value on my input. Unfotunanently, I don't know why? I'm rendering BuyPlace component. In this component I have form which has Input c...

4

Solved

I'm testing a couple of components that reach outside of their DOM structure when mounting and unmounting to provide specific interaction capability that wouldn't be possible otherwise. I'm using ...
Quodlibet asked 15/3, 2017 at 9:0

3

I'm trying to run jest --coverage --watch so that I only get the coverage for whatever component I'm writing tests for and I can see the increased coverage as I write more tests. But while the modi...
Shanleigh asked 18/10, 2019 at 8:28

19

Solved

I trying to collect test coverage for this project using yarn test --coverage # i.e. "react-scripts test --coverage" My jest config is this: "jest": { "collectCoverageFrom": [ "src/**/*.ts*"...
Calipash asked 11/8, 2019 at 14:54

5

Solved

So I'm using Jest, Typescript and Create-react-app I have this test: import { defaultHeaders } from './http'; describe('http tests', () => { test('defaultHeaders()', () => { const headers ...
Facing asked 11/9, 2020 at 20:18

13

I'm writing a Jest mock, but I seem to have a problem when defining a mocked function outside of the mock itself. I have a class: myClass.js class MyClass { constructor(name) { this.name = name;...
Jadwiga asked 21/8, 2018 at 23:0

10

Solved

I'm trying to write tests for a react component I've built that utilizes navigator.geolocation.getCurrentPosition() within a method like so (rough example of my component): class App extends Compo...
Trevino asked 24/3, 2017 at 20:51

11

Solved

I am doing a basic end to end testing here, for the moment it's failing, but first I can't get rid of the open handle. Ran all test suites. Jest has detected the following 1 open handle potentiall...
Bartholomeus asked 19/7, 2021 at 8:57

6

I'm trying to upgrade my project to React 18, everything works in dev and production mode in the browser. But after upgrading to the latest version of @testing-library/react some of my unit tests a...
Villous asked 25/4, 2022 at 17:24

2

Solved

Can anyone explains me the difference between line coverage and statement coverage in jest. When I ran my coverage report I got a different line coverage percentage compared to statement.
Anglesey asked 21/1, 2020 at 17:59

2

Solved

I need to mock an imported CSS file in my jest/enzyme test: Header.test.js import React from 'react' import { shallow } from 'enzyme' import { Header } from './Header' jest.mock('semantic-ui-css...
Galactic asked 17/2, 2018 at 13:22

8

Solved

Is it possible to access an object's key inside the name portion of a .each? let accounts = [ { details: { company_name: "company_name", email, password: "asdf", }, find: [ "_id", "c...
Infinite asked 28/6, 2019 at 1:49

© 2022 - 2024 — McMap. All rights reserved.