Questions tagged [enzyme]

Unit test library for React. It is developed by Airbnb. It can be used with other JavaScript testing frameworks like Mocha, Jest, Karma, etc.

Enzyme is a JavaScript testing utility for React that makes it easier to assert, manipulate, and traverse your React components' output.

Enzyme's API is meant to be intuitive and flexible by mimicking jQuery's API for DOM manipulation and traversal.

Enzyme is unopinionated regarding which test runner or assertion library you use and should be compatible with all major test runners and assertion libraries out there. The documentation and examples for Enzyme use Mocha and Chai, but you should be able to extrapolate to your framework of choice.

4320 questions
2
votes
0 answers

Can't find Rendered Component via - react-router

I can't find my rendered DashBoard component. I'm using enzyme's mount(). I get an instance of back after mounted so not sure how I can find() my component as it doesn't recognize find() on a wrapper jsdom.js const jsdom = require('jsdom') const…
PositiveGuy
  • 17,621
  • 26
  • 79
  • 138
2
votes
2 answers

Testing React component with dynamic import (Enzyme/Mocha)

I'm trying to test a React component using Mocha and Enzyme that uses a dynamic import to load a module. When I try to test the logic that relies on the dynamic import I get incorrect results. The problem is that the async functions don't finish…
anthonator
  • 4,915
  • 7
  • 36
  • 50
2
votes
1 answer

MemoryRouter TypeError: Cannot read property 'pathname' of undefined

I have a redux container which I want to mount in my test case. It has a component which is using react-router link. Mounting the container was throwing me history not defined error, after reading this…
Minato Namikaze
  • 576
  • 1
  • 7
  • 22
2
votes
0 answers

Enzyme tests for higher order components - redux

I have spent some time online searching for documents around how to do this. There seems to be a few ways. But I am not sure on which is the best way to do this. This is what I have so far My HOC interface IStateProps { errorState: IErrorState; …
suprita shankar
  • 1,554
  • 2
  • 16
  • 47
2
votes
1 answer

Triggering this.props.dispatch in a test environment

Hello I have a Jest / Enzyme test like this: it('triggers checkbox onChange event', () => { const configs = { default: true, label: 'My Label', element: 'myElement', } const checkbox = shallow(
SeanPlusPlus
  • 8,663
  • 18
  • 59
  • 84
2
votes
2 answers

Not getting the simulate event to work to trigger click

I am trying to test a react component but somehow I am not able to get the simulate function to trigger the click and therefore I am not able to test the state variable or check for the function call of the click handler. Here is the component…
Ayan
  • 21
  • 2
2
votes
1 answer

.innerText in component method code does not work properly in enzyme testing. Testing react component with Jest+Enzyme(mount())

Using React+Enzyme+Jest Hello, I used .innerText property to get value of certain element, see line #5 of my code: _modifyProfileField (event) { const { currentAgentProfile, agentsDatabase } = this.state; const eventTarget = event.target; …
Dmytro Zhytomyrsky
  • 1,371
  • 2
  • 11
  • 17
2
votes
0 answers

How should I mock out react-native-extended-stylesheet in Mockery.js?

I have started using ava.js in my react native project. I have an AVA setup file that looks like this (from the Ignite starter project): import mockery from 'mockery'; import m from 'module'; // inject __DEV__ as it is not available when…
sinewave440hz
  • 1,265
  • 9
  • 22
2
votes
1 answer

Can't simulate enzyme test click on a material ui Checkbox when nested in a redux-form Field tag

I am trying to perform an enzyme/mocha/chai test to simulate changing the state of checked from true to false in a materialUI Checkbox tag which was wrapped in and rendered by a redux-form Field. I am able to simulate clicks on native components…
Vaughn Walters
  • 75
  • 3
  • 11
2
votes
1 answer

Get updated state of component when calling method on class via enzyme

How can I get my test to reflect the new state of my component after calling updateItem on it. I did try rendered.update() but I must be missing on how something works. Thanks. Method on class: updateItem (id) { return updateItem(id) …
groovy
  • 275
  • 1
  • 2
  • 10
2
votes
0 answers

Setting the baseRoot for mocha babel-register: "Cannot find module 'atoms/histogram',"

I've a project with this current layout: ├── atoms │   ├── histogram ├── molecules │   ├── many-histograms And since I didn't want to use ugly relative paths in my imports, I've set the paths property for the Browserify. So in…
Heikki Mustonen
  • 301
  • 3
  • 15
2
votes
0 answers

Unable to get Response from Redux action using Mocha Enzyme

I am using Enzyme to unit test my React components. In my use case I want to validate login by setting state value and after simulating click event we must be able to get response from action. Container import React, { Component } from…
UIseeker
  • 97
  • 1
  • 11
2
votes
1 answer

Trigger event keyDown on Contenteditable element (testing + react + jest + enzyme)

I am using enzyme + jest to test react App, is it possible to trigger onKeyDown event on contetnteditable span element? Editable text I tried: result.find('#name').simulate('keyDown', { key: 'm',…
Dmytro Zhytomyrsky
  • 1,371
  • 2
  • 11
  • 17
2
votes
1 answer

Enzyme reference error - unable to access window functions

I have the following function in main.js (loaded with node.exe): window.onload = () => { window.getString = function () { return value; }; } Following is my test case written using Enzyme and Mocha import…
morghulis
  • 145
  • 11
2
votes
0 answers

How to unit test a component that depends on React Router?

I'm pretty new with unit testing React, not unit testing in general and I have a couple of questions. I do have a component which represents a page on which a user can authenticate. Now, I do want to test this component, but I'm unsure which…
Complexity
  • 5,682
  • 6
  • 41
  • 84