Questions tagged [jestjs]

Jest is a JavaScript unit testing framework made by Facebook based on Jasmine and provides automated mock creation and a jsdom environment. It's often used for testing React components.

It has a couple of advantages compared to vanilla

  • Automatically finds tests to execute in your source code
  • Automatically mocks dependencies when running your tests
  • Allows you to test asynchronous code synchronously
  • Runs your tests with a fake DOM implementation (via ) so that your tests can be run on the command line
  • Runs tests in parallel processes so that they finish sooner

Resources

22701 questions
9
votes
1 answer

'test' is not defined. (no-undef)

I'm using eslint(JavaScript Standard Style) with jest lint keeps me warning about jest's functions are not defined. I tried /* eslint-env jest */ It works but, I don't want to use it in every test.js file. so I tried. .eslintrc (in root…
JillAndMe
  • 3,989
  • 4
  • 30
  • 57
9
votes
1 answer

How to test axios interceptors using jest?

I'm trying to test the following code: import axios from 'axios'; import { history } from './ReduxService'; axios.interceptors.response.use(response => response, (error) => { if ((error.response && error.response.status === 408) ||…
9
votes
3 answers

Jest cannot find module from node_modules

I'm creating typescript base npm module, but i stuck with jest tests. I'm trying to include jsonld module from https://github.com/types/jsonld and everything seems work fine, but when i run command yarn test i have error message Cannot find module…
Vytautas Saulis
  • 141
  • 2
  • 6
9
votes
4 answers

vue-test-util click trigger on button not firing

I have a Vue component with a button. On a button click, a method is called. I am using Jest for unit test. I expected .trigger method from vue-test-utils to create a synthetic event on the button, but it does nothing. I tried calling the method…
Payam Mesgari
  • 953
  • 1
  • 19
  • 38
9
votes
4 answers

Jest testing with Node - Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout

I'm starting to test my code with Jest, and I can't make a seemingly simple test to pass. I am simply trying to check if what I receive from a Maogoose database request is an object. The function fetchPosts() is working because I hooked it up with a…
mokiliii Lo
  • 587
  • 3
  • 13
  • 26
9
votes
1 answer

How to test conditional rendering of components using Jest and Enzyme

I have a conditional rendering block in my React component which is defined as: {(props.email.primary.isPending) ? :
pranami
  • 1,381
  • 5
  • 22
  • 43
9
votes
4 answers

React Jest Snapshot testing with dynamic Id

I am facing attached error while performing snapshot testing. The error is basically for dropdown and datepicker of kendo controls.
Parag Pathari
  • 281
  • 2
  • 5
  • 19
9
votes
1 answer

react-testing-library - fireEvent.select() not working

I'm currently running some tests for a project I'm working on, and am having trouble using fireEvent.select() as a way to focus on an input field. My test so far: it('is not working :(', () => { const input = queryByPlaceholderText('blah'); …
Zach
  • 871
  • 1
  • 11
  • 21
9
votes
1 answer

Configuring Jest in WebStorm

I'm trying to use Jest to aid Puppeteer testing in WebStorm. It is my first time using Jest and it looks just the framework I need to help with testing, assertions, setup and teardown etc... Trouble is, WebStorm won't recognise the keywords e.g.…
Steerpike
  • 1,712
  • 6
  • 38
  • 71
9
votes
3 answers

VSCode Newbie: Remote Jest/Node debugging through Docker

I've recently switched from Vim to VSCode, and I'm trying to set up VSCode debugging for jest tests run through docker. The debugging works...sort of. If I want to run jest tests and have breakpoints activate, I need to: Insert the…
PlankTon
  • 12,443
  • 16
  • 84
  • 153
9
votes
1 answer

Jest's testRegex and testMatch

Can anyone explain to me what is the difference between testRegex and testMatch in Jest configuration? (https://jestjs.io/docs/en/configuration) I understand that I should not define them both but in what situation shall I use one and not the other?
Ziv Levy
  • 1,904
  • 2
  • 21
  • 32
9
votes
1 answer

How do I supress JSDOM errors in Jest?

I have an issue where a 3rd-party library is using some valid CSS parser features that are not available in JSDOM, and I'd just like to suppress those kinds of errors. But given that I'm using JSDOM through Jest, I'm not quite sure how to do that. I…
jktravis
  • 1,427
  • 4
  • 20
  • 36
9
votes
3 answers

How to test default props functions is attached to component or not ? | React | Jest | Enzyme

How can we write the test to check defaultProps function in this case ( handleChange: () => {},handleBlur: () => {},handleSubmit: () => {}) attached to dom and they are working correctly? I know we can test function when we pass as props but…
Rutul Patel
  • 663
  • 2
  • 10
  • 23
9
votes
3 answers

Run specific jest project

I'm setting up a lerna monorepo with jest, I'm using jest's projects like so: projects: ['/packages/*']. Running tests work as expected, however, I'm not sure how can I run a specific project? Say I have: /packages jest.config.js /core …
donzul
  • 405
  • 1
  • 4
  • 13
9
votes
3 answers

How can I mock all the named exports from a module, except one?

I have a redux file that contains my reducer and all of my actions via named exports. export const reducer = (state, action) => ... export myAction = action => { return {type: 'ACTION', action} } ... When in my test file I import the reducer…
JeffBaumgardt
  • 1,378
  • 3
  • 16
  • 24