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
1 answer

How do I test an element that is outside the enzyme wrapper?

I'm using Jest and Enzyme to do unit tests. In my test.js file I have let wrapper = mount( My test clicks a button in the wrapper wrapper.find('button').simulate('click') and the component renders a modal that is outside the wrapper. I need…
radical
  • 51
  • 7
2
votes
0 answers

Import is undefined in Jest snapshot test

I'm using Jest and Enzyme to snapshot test a component that uses CSSTransition from react-transition-group (v2.1.0). When I create a snapshot of the component, CSSTransition appears undefined. This causes React to throw a warning: Warning:…
ajgreenb
  • 21
  • 2
2
votes
1 answer

React/Jest/Enzyme: How to test adding text to input and checking for that text?

We have a form with a simple input and submit button. Upon submit, there will be li's added inside of the section.user-list. After typing ni and clicking the Search button, 2 lis will enter the view, one of them containing "Nick Sims" However…
Leon Gaban
  • 36,509
  • 115
  • 332
  • 529
2
votes
1 answer

How to test React component class methods

I have a React component that I am attempting to test some of its instance methods, but I am having trouble understanding how I am supposed to do it. The issue that is tripping me up is the fact that I am referring to this.setState() in the test and…
dericcain
  • 2,182
  • 7
  • 30
  • 52
2
votes
1 answer

Unit testing select element's `onChange` function with Enzyme

I have a dropdown component in React that renders a select element with some options. Here is what my test looks like: import React from 'react'; import { shallow, mount } from 'enzyme'; import expect from 'expect'; import Dropdown from…
Ralph David Abernathy
  • 5,230
  • 11
  • 51
  • 78
2
votes
0 answers

Running Intern with React Prop-Types?

I am trying to move my team to 15.6.1 of React. As such, prop-types are now a separate package. Currently, when running Intern tests with Enzyme, it fails to execute because of the following: Running "intern:runner" (intern) task SUITE ERROR Error:…
2
votes
1 answer

Mocha: TypeError: Converting circular structure to JSON

Mocha suddenly is throwing TypeError: Converting circular structure to JSON I have done a new setup for executing the test cases. The test cases were running fine till yesterday. I am using: Mocha, Chai, Sinon, Enzyme This is my package.json: { …
Soham Nakhare
  • 425
  • 4
  • 18
2
votes
1 answer

Enzyme testing reach component, giving error

I have the following react component which I am trying to unit test using enzyme and jest. import React from 'react'; import { Subject } from 'rxjs/Subject'; import { connect } from 'react-redux'; import styles from…
tmp dev
  • 8,043
  • 16
  • 53
  • 108
2
votes
2 answers

Unit test with redux-mock-store - How can I make this unit test pass?

I've just started using jest and enzyme. I'm having a problem to make my unit test work. Im using redux-mock-store to mock store object. it('shows an li for each comment', () => { expect(container.find('li').length).toBe(2); }); I'm expecting…
user5809117
2
votes
1 answer

Running react unit test with scss

I have a react component that is using a scss file. The scss file is as follows $searchImage: url('../../../stylesheets/images/Search.svg'); .srchBoxContaner { padding: 1.5rem 1.5rem 0rem 1.5rem; } The react component is a standard component…
tmp dev
  • 8,043
  • 16
  • 53
  • 108
2
votes
5 answers

Why does shallow Rendering not work as expected?

I am using enzyme for test my create-react-app component, but It did not work intuitively. Am I misunderstanding what shallow rendering is? import React from "react"; import { Card } from "./Card"; const TestUser = () => { return (
Liuuil
  • 1,441
  • 3
  • 16
  • 22
2
votes
1 answer

React integration with cucumberjs

I am working on a React-Nextjs project and trying to integrate the BDD tool cucumber for specification and feature level testing. Though am having some trouble integrating cucumber with React when using enzyme to shallow render the component: Here's…
user988544
  • 556
  • 1
  • 11
  • 32
2
votes
1 answer

Why is this Jest/Enzyme setState test failing for my React app?

Expected: Test runs and state is updated in the Login component, when then enables the Notification component (error message) to be found Results: Test fails, expected 1, received 0 Originally before I added redux and the store, thus needing to use…
Leon Gaban
  • 36,509
  • 115
  • 332
  • 529
2
votes
1 answer

React tests with jest, enzyme behave strangely

I am setting up unit tests for testing React components with Jest and enzyme. Somehow my setup works strangely. When the component under test is inside the test file everything works as it should, but when it is imported, it doesn't. The…
gbdornala
  • 23
  • 2
2
votes
2 answers

How can fetch be mocked in a class component's instance method in React?

I'm working with create-react-app, jest and enzyme. I have a class component that loads "detail" data when a table row is clicked, then displays a form in a modal where the details can be edited and saved: import React, { Component } from…
user6689821
  • 147
  • 11