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
2 answers

React, Enzyme : Cannot read property 'history' of undefined

I was trying to test my components and everytime my tests fail, and i'm not able to figure out where the problem is located. Login.test.js : import { Meteor } from 'meteor/meteor'; import React from 'react'; import expect from 'expect'; import {…
Kaldrogh
  • 73
  • 1
  • 2
  • 4
2
votes
1 answer

Enzyme / Karma / Webpack / Jasmine / React testing not working

I've install as per the documentation npm i --save-dev enzyme npm i --save-dev react-test-renderer react-dom (currently using React 15.5.4) And altered my karma.conf file http://airbnb.io/enzyme/docs/guides/karma.html and…
Rory
  • 1,442
  • 4
  • 21
  • 38
2
votes
1 answer

Wait on all promises in a simulate call

I am using Jest and Enzyme to test React components. My React component (under test) has a remote select component. When the user types some text, data is fetched from API and the options are displayed. test('should fetch data', () => { // mock…
vijayst
  • 20,359
  • 18
  • 69
  • 113
2
votes
1 answer

testing custom react methods with jest and enzyme

I am trying to test a method within a react component. The component is a form and it should be testing the handleSubmit() method gets called when the submit button is clicked. I have tried the below. it('handlesSubmit when submit button is…
Mantis
  • 1,357
  • 3
  • 27
  • 49
2
votes
1 answer

How can I test the text of a child element in enzyme?

Using enzyme, I'm attempting to test the rendered text of a component. The component is a LinkButton, and it renders out like so: I'm not sure how to directly reference the string "See…
Mark Chandler
  • 338
  • 1
  • 3
  • 9
2
votes
1 answer

Calling a function from a parent class to test the child class

I'm a writing a test with Jest and Enzyme to test the functionality of a component in a React Native application. There is a parent component and a child component that used a method in the parent to instantiate. To elaborate, here is a abridged…
Justus Eapen
  • 1,139
  • 10
  • 22
2
votes
0 answers

Writing unit tests for Redux Form component without it being "connected"

Early on with an app I built, I split out the Redux Form stuff in the component in the following way: import React, { PropTypes } from 'react'; import { Field, reduxForm } from 'redux-form'; import {renderInput, required, email} from…
kinabalu
  • 428
  • 1
  • 5
  • 10
2
votes
1 answer

Testing for text contained in React component with Enzyme and Jest

For my React component I have the following: const ArchiveButton = ({collection, onClick}) => { return ( { collection.archived &&
2
votes
1 answer

Simulate onClick event in enzyme

I have this code in my Search component render method: and then I have this: handleSearch = (e) => { this.setState(prevState => ({ …
The worm
  • 5,580
  • 14
  • 36
  • 49
2
votes
2 answers

Detect synthetic click in React during testing with Jest/Enzyme

I am building an app with React. I am hiding a file input element () "behind" a react-bootstrap Button to be able to control styling. So, when the button is clicked I turn around and fire a synthetic click event on the text input…
Andrew Willems
  • 11,880
  • 10
  • 53
  • 70
2
votes
2 answers

Testing for component/props is undefined with Enzyme in ReactJS

I'm trying to test if the LoginContainer component via props exists in the Header with Enzyme, but I'm not having luck. Here's my main app: import React from 'react' import Header from '../components/Header' import LoginContainer from…
angular_learner
  • 671
  • 2
  • 14
  • 31
2
votes
1 answer

React Native Jest Enzyme Find and Press Component

i'm trying to be adventurous and im trying to get 100% code coverage on my personal project. and i cant the documentation that explains how to simulate a click event using jest, enzyme and react-native.
X0r0N
  • 1,816
  • 6
  • 29
  • 50
2
votes
2 answers

Why doesn't enzymes find() with component props work the same way when using full rendering or shallow rendering?

According to the enzyme documentation for find() for shallow rendering and full rendering (mount), one should be able to look up components using the value of props. This does not seem to work the same way for full and shallow rendering thought I…
zwalker
  • 346
  • 5
  • 9
2
votes
2 answers

What method of render adds to the DOM?

How to render with enzyme a component or element to be added into the DOM? // pseudocode let wrapper = (shallow or mount or render)(
); console.log(wrapper[?].getBoundingClientRect().width); //…
user220409
  • 184
  • 1
  • 17
2
votes
2 answers

Trouble testing button onClick handler with Enzyme

I am having trouble using Enzyme's contains method when it comes to a button's onClick handler where the provided action method requires an argument. I ran into this while passing redux actions to a component, but I'll use simplified examples…
devboell
  • 1,180
  • 2
  • 16
  • 34