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

Testing material-ui's SelectField with jest

I am trying to figure out the proper way of testing material-ui's SelectField component with jest. I need to simulate change with certain parameters. What I have for now: it('when SelectField with id city_id changed, onFilterChanged prop should be…
Max Larionov
  • 420
  • 6
  • 19
2
votes
1 answer

Enzyme not shallow rendering child

I am trying to test that a child component exists by shallow-rendering it with Enzyme. However, it does not appear to be getting past the return of the component and instead shallow-renders . MainComponentContainer.js import PropTypes…
JBd
  • 115
  • 2
  • 9
2
votes
1 answer

How do I test a callback of a React component wrapped in withRouter?

I'm using Jest and Enzyme to test a React project written in TypeScript. I have a component that is wrapped in a React-Router router, and which looks somewhat like this: import { SomeButton } from './someButton'; import { RouteComponentProps,…
Vincent
  • 4,876
  • 3
  • 44
  • 55
2
votes
2 answers

Enzyme 3 get attributes of rendered DOM-node

I get this html from myDomNode.html();
{{someChildren}}
In my test I want to check that aria-expanded is set to true. With enzyme 2.x and react 15.x this was working:…
mstruebing
  • 1,674
  • 1
  • 16
  • 29
2
votes
1 answer

Testing image's 'naturalHeight' without DOM

I'm writing a JS test to check that an image's css class is being applied properly. The class is computed based on the image's naturalHeight property. However, because this is a JS test, there is no DOM, so naturalHeight is always 0 in testing. How…
devthorne
  • 197
  • 13
2
votes
0 answers

Enzyme find node created with createContainer (React.PureComponent)

I have a wrapper component similar to the following: /* Some imports here */ class Wrapper extends React.Component { renderChildren() { const { children } = this.props; return children.map(child => ); …
juhojo
  • 43
  • 5
2
votes
0 answers

jest + enzyme: how to handle async image.onload inside 3d party library

I'm writing unit tests using Jest and Enzyme for my component, which uses 3rd party library (CropperJs), where there is event listener set on image upload. There is 'new Image' object created inside library with the source that I pass in base64…
Wedmich
  • 169
  • 1
  • 9
2
votes
1 answer

React-jest-enzyme: testing callback of child component that calls another function first before calling the callback

I am testing wether a callback that is passed to a child component is called after my button in the child component is clicked. I simulate the react-bootstrap button, , by using the .simulate('click') function. The problem is that…
2
votes
1 answer

Creating HTML elements for javascript testing

So i have a particular problem, inside my react component i used commands like…
Eliâ Melfior
  • 359
  • 4
  • 19
2
votes
3 answers

How to use enzyme ShallowWrapper to find a React Component stored as a prop in another React Component?

I have a jest/enzyme test which creates a ShallowWrapper around a component, finds a specified semantic-ui-react Button (by id), simulates a click on the button, and then looks to see if the click toggled certain content. Sample JSX:
FrostyFox
  • 103
  • 2
  • 7
2
votes
0 answers

React Component instance method spy never getting called when triggered by window event

I have a component that triggers a component instance method on a window event (resize & scroll). I am trying to spy on the event handler, but the spy never gets called. Here is my component: class PopOverContainer extends PureComponent { static…
Adam Duro
  • 882
  • 1
  • 9
  • 21
2
votes
2 answers

Testing a react component with a connected child component using enzyme mount

I'm testing a react component using enzyme mount (because i'm testing it's lifecycle methods). My problem is that my component has a redux connected child component, which is giving me the error: Invariant Violation: Could not find "store" in…
Uri Klar
  • 3,800
  • 3
  • 37
  • 75
2
votes
0 answers

Enzyme Unit tests with Webpack Externals

I'm currently testing a component that relies on a an external script with webpack externals. DBPanel.js: import React, { PureComponent } from 'react'; import $ from 'jquery'; And the webpack externals file looks like…
Jerry Tsui
  • 21
  • 2
  • 3
2
votes
1 answer

Simulate click - enzyme

I have a problem with Enzyme tool to test React app. In my component I have login form and I want to test if after click on button the p tag will fill by text. In fact after clicking submit there is sent request to the api (which doesn't exist now),…
c00per
  • 53
  • 1
  • 4
2
votes
1 answer

Should .jest directory be gitignored?

Hey guys I have a project running jest and enzyme in react native and I'm wondering if the directory .jest should be gitignored?
CommonSenseCode
  • 23,522
  • 33
  • 131
  • 186