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

testing react component with enzyme

Say I have the following component: export default class CustomInput extends PureComponent { render () { return (
Abraham P
  • 15,029
  • 13
  • 58
  • 126
2
votes
2 answers

Enzyme form onsubmit is not getting called

I couldn't find an appropriate answer to this anywhere. I hope it's not a duplicate. I have a simple enzyme test script to simulate form submission that I wrote using Reactjs in ES6 syntax. I am using mocha as my test runner. When I try to simulate…
morghulis
  • 145
  • 11
2
votes
1 answer

React-Redux Connected Component testing correct action has been dispatch on click event

I'm a newbie to testing react-redux components with jest and enzyme, and so far i've be finding this a challenge. I have a login page, and i want to test that the correct error action is dispatch if login fails after the login button is clicked. So…
user3162979
  • 855
  • 2
  • 10
  • 17
2
votes
1 answer

How to mock a method which being called from render method using shallow (enzyme)

I need to Mock getZvalue so , when i do a shallow based on z value i will try to render something different . How do i test it . Below is sample code . can i spy this method to return a value class AbcComponent extends React.Component{ render(){ …
Kamaraju
  • 2,365
  • 2
  • 15
  • 17
2
votes
2 answers

Test that a component does not render when passed a certain prop value with enzyme

I am wanting to test if my LoadingIndicator component loads into the DOM when the status property is set to FETCHING and doesn't load when it is READY. Right now I have this: import React from 'react'; import { assert } from 'chai'; import {…
Alioo
  • 417
  • 1
  • 4
  • 19
2
votes
2 answers

Testing existence of connected component with react-redux

I'm trying to test a component that wraps a connected component. So I have (simplified): const InnerComponent = () => { return (

Hi!

) } const InnerComponentWrapper = connect()(InnerComponent) const OuterComponent = () => { return…
Alon Dahari
  • 1,138
  • 1
  • 9
  • 27
2
votes
1 answer

How to properly test react component methods

I've been developing in React for a while for my work, but recently I was requested to get some applications to ~100% test coverage using Istanbul. I've wrote over 160 tests for this application alone in the past few days, but I haven't been able to…
Munsterberg
  • 758
  • 4
  • 17
  • 37
2
votes
1 answer

How to test that a sub component doesn't exist with React+enzyme

Lets say I have a component that has a prop that controls whether a button is shown or not. I'm adding the following test to make sure that the prop is always observed. import React from 'react'; import { expect } from 'chai'; import { mount } from…
DiverseAndRemote.com
  • 19,314
  • 10
  • 61
  • 70
2
votes
0 answers

Simulate "ended" event using enzyme in test?

Hello I am trying to simulate an 'ended' event on and HTML5 audio element without success. Here is my component: export class AudioPlayer extends Component { constructor (props) { super(props); // Auto play turned off when…
Nicolas
  • 1,193
  • 1
  • 10
  • 25
2
votes
2 answers

React js unit tests for connected components - mocha

I have a smart component, trying to write unit test (DOM tests) - getting the following error: Not sure why I am getting this error even though I am passing props in the test..? Invariant Violation: Could not find "store" in either the context or…
monkeyjs
  • 604
  • 2
  • 7
  • 29
2
votes
1 answer

Mocha & Enzyme - How to test that React component has no children?

For testing I am using mocha and enzyme along with chai and chai-enzyme for test assertations. Say I have the following presentational component in React: import React from 'react' import { Component, PropTypes } from 'react'; const LayerList =…
therewillbecode
  • 7,090
  • 4
  • 35
  • 42
2
votes
2 answers

I get a contextTypes error when I try to test a very simple component

I am new to reactjs and trying to write a unit test for a simple function. I am using enzyme and here is my test: import React from 'react'; import { shallow } from 'enzyme'; import {P} from "../../src/app/components/T"; import ToDoItem from…
Hamed Minaee
  • 2,480
  • 4
  • 35
  • 63
2
votes
0 answers

test state of react component using enzyme shallow

I have a component with following constructor. constructor(props) { super(props); this.state = { displayCluster: {} }; } In my test, when I do shallow render and try to test the null state value of displayCluster. It prompts for…
Varun Gupta
  • 1,419
  • 6
  • 28
  • 53
2
votes
1 answer

Issues Testing React-Bootstrap Components

I am having some difficulties when testing components that use React-Bootstrap with Mocha, Chai, and Enzyme. Hopefully someone can key me into what I am doing wrong. When testing components that do not use React-Bootstrap, I notice that the output…
user3079061
  • 229
  • 4
  • 12
2
votes
1 answer

Testing React PropTypes with sinon

As an example I used Make React PropType warnings throw errors with enzyme.js + sinon.js + mocha.js. I have a React component with one required prop: class Pagination extends Component { render() { return ( ... render some…
Alekstim
  • 452
  • 1
  • 8
  • 19
1 2 3
99
100