Questions tagged [chai-enzyme]
28 questions
24
votes
4 answers
Checkbox is not `checked` after simulate `change` with enzyme
I tried to use enzyme to simulate change event on a checkbox, and use chai-enzyme to assert if it's been checked.
This is my Hello react component:
import React from 'react';
class Hello extends React.Component {
constructor(props) {
…

Freewind
- 193,756
- 157
- 432
- 708
23
votes
4 answers
Error: Method “props” is only meant to be run on a single node. 2 found instead
it('should call setCampaignDate on click', function () {
let spySetCampaign = sinon.spy(wrapper.instance(), 'setCampaignDate');
let datePickers = wrapper.find('.campaign-date-tab').dive().find(Datepicker);
…

user3725876
- 235
- 1
- 2
- 6
15
votes
2 answers
Testing changes to React component state and spying on instance methods using enzyme
I am working on a wrapper component for smoothly loading images in React. I use enzyme with mocha, chai and sinon to unit test my component. In the test here, I am trying to test that the:
component's state is updated when the image has loaded
the…

vamsiampolu
- 6,328
- 19
- 82
- 183
6
votes
2 answers
Enzyme Test React.createRef()
I have a commponent where I use the new React.createRef() api, how to test document.activeElement should be equal current ref commponent.
component :
export class Automatic extends Component {
componentDidMount = () => this.focusContainer()
…

Palaniichuk Dmytro
- 2,943
- 12
- 36
- 66
4
votes
1 answer
How do I apply Chai plugins across bundles in Karma?
I'm running tests using Karma + Mocha + Chai + Webpack. I'm want apply multiple Chai plugins to my tests. I'm using the Karma config below, which splits my tests into multiple bundles.
I tried to use karma-chai to create a global chai instance, then…

Arion
- 1,792
- 2
- 18
- 29
3
votes
1 answer
How to test window.open is being called from a react component
I have a react component that renders a series of other components, each with their own checkbox.
There is a state hook called rulesToDownload which begins as an empty array and has ids added to / removed from it as checkboxes are checked /…

PeteG
- 421
- 3
- 17
3
votes
1 answer
Invoke a function with enzyme when function is passed down as prop - React
I have a function say onClickOfCreateAccountButton which is being called from my Child Component on click of a button but the logic is written in the Parent Component.
How do I simulate it?
My code:
onClickOfCreateAccountButton() {
const el…

vini
- 4,657
- 24
- 82
- 170
2
votes
1 answer
How to test React components inside react-responsive tags
Inside a component I am using react-responsive components to distinguish between rendering mobile and desktop content.
export class MyComponent extends React.Component {
//...
render() {

NotYanka
- 507
- 1
- 6
- 12
2
votes
0 answers
Cypress error : Error: Cannot find module './preprocessor' from '/Users/stein/node_modules/parse5/lib/tokenizer'
When I execute the cypress test
import React from 'react';
import ReactDOM from 'react-dom';
import { configure, shallow } from 'enzyme';
import { expect } from 'chai';
import ProcutList from '../../src/components/ProductList';
import Product from…

stein korsveien
- 1,047
- 5
- 13
- 35
2
votes
1 answer
How to get css values of a dom element using Jest, Enzyme or any other unit testing library/framework?
Is it possible to get any css value out of the DOM element being tested using Jest, Enzyme, Chai, etc.? From what I have seen so far, you can only get those css values that are mentioned in the code as style objects. But I'm not finding a way to get…

Rahul Dole
- 2,723
- 2
- 24
- 30
2
votes
1 answer
How to stub dynamical import with Sinon JS
I try to stub with sinon js the import, how actyally to do that,
import XLSX from 'xlsx'
beforeEach(() => sinon.stub(sheetJS).resolve({})) - does not work for me, and I cath error that resolve is not a function
export default (data, sheetName,…

Palaniichuk Dmytro
- 2,943
- 12
- 36
- 66
2
votes
1 answer
Test image onload inside react component using enzyme, sinon
I'm trying to test that a function callback is being called for an image inside my component.
This is the component:
const ImageById = (props) => {
return (
…

rareyesdev
- 2,337
- 1
- 25
- 43
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
1
vote
1 answer
Having trouble spying on an action within a component test
I'm trying to test for a dispatched action using chai-spies. I've tried various trouble shooting techniques, but have been unable to get the test to pass.
I've attempted to spy on both the (component.prototype, 'method) and…

JoshingYou
- 113
- 7
1
vote
0 answers
testing a state change on react after calling an async method
I have a React component that does something like:
Component
class CallBackend extends React.Component{
constructor(){
super();
this.state = {
message:"",
loading:true
};
}
callService =…

Anyul Rivas
- 655
- 2
- 12
- 31