enzyme

TypeError: Cannot read property 'equal' of undefined

大兔子大兔子 提交于 2019-12-13 12:57:47
问题 I am trying to use enzyme to assert DOM nodes. My Component looks like import React, {Component} from 'react'; import TransactionListRow from './TransactionListRow'; import {Table, TableBody, TableHeader, TableHeaderColumn, TableRow} from 'material-ui/Table'; export default class TransactionList extends Component { render() { const { transactions } = this.props; return ( <Table> <TableHeader displaySelectAll={false}> <TableRow> <TableHeaderColumn>Name</TableHeaderColumn> <TableHeaderColumn

ReactWrapper " Requires that state not be null or undefined

◇◆丶佛笑我妖孽 提交于 2019-12-13 04:16:09
问题 Trying to Render Modal but keep getting the following error: TypeError: ReactWrapper::state("descriptionModalOpen") requires that state not be null or undefined Test file : I have tried the same method in other files and it worked just fine it("renders a modal portal", () => { const isOpen = wrapper.state("descriptionModalOpen"); const modalPortal = wrapper.find(".fullmodal"); expect(isOpen).toBeTruthy; expect(modalPortal).toHaveLength(1); expect(toJson(wrapper)).toMatchSnapshot(); }); });

How to mock api in jest and enzym

喜夏-厌秋 提交于 2019-12-13 04:14:24
问题 This is the method which I use for making fetch calls to my api: static sendJsonRequest(address, action, requestType, jsonData, queryParams, successCallback, errorCallback){ var finalURL = Client.getServiceURL( address, action, queryParams); fetch(finalURL, { method: requestType, headers: { 'content-type': 'application/json; charset=utf-8', 'Authorization': 'Bearer ' + localStorage.getItem("access_token"), 'pragma': 'no-cache', 'cache-control': 'no-cache' }, body: String(requestType)

Testing components with Jest fails

北战南征 提交于 2019-12-13 02:43:50
问题 I am new to Jest and Java Script in general. I wrote a test to one of my components but it seems to fail and I can't figure out how to fix it and what is wrong (Apparently something with enzyme). It prints: ● Console console.log src/App.js:18 props = {} console.log src/App.js:19 url = ./api/user/undefined/ C:\Users\Itay\Documents\Matan - Microsoft\Matan\MatanClient\node_modules\react-dom\cjs\react-dom.development.js:62 throw error; ^ Invariant Violation: The `document` global was defined when

ReferenceError on enzyme import

ε祈祈猫儿з 提交于 2019-12-13 00:47:13
问题 I'm trying to write a basic test for a react-native component using enzyme and jest. I get an error alluding to enzyme not being imported correctly: ● SearchPage › it starts spinner when page is loading - ReferenceError: _enzyme is not defined at Spec.eval (__tests__/basic-test.js:12:16) 1 test failed, 0 tests passed (1 total in 1 test suite, run time 1.113s) npm ERR! Test failed. See above for more details. I have tried reinstalling the enzyme package and blindly fiddling with the code as I

How to access Child component state and lifecycle methods and validate in React with Jest+Enzyme?

穿精又带淫゛_ 提交于 2019-12-13 00:35:51
问题 Need help with enzyme for testing. I have checked here but it did not help: How does one access state on a nested React component wrapped by an HOC? Here is my problem: How can I check function called or not and state of Child component? I also need to check lifecycle, so I used mount of parent component, but haven't done that yet. I used below when I render ed one component: expect(searchWrapper.find('select [selected]').val()).to.equal('someId') , but with mount , this is not working, as it

Testing react components: Jest encountered an unexpected token

无人久伴 提交于 2019-12-12 17:19:06
问题 I am trying to test with Jest, but got an error: Jest encountered an unexpected token This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript. I have a photo gallery app and whenever I click on an image, a modal pops up with an image. I want to test that when I click on the image, the popup shows or exists. Is there a way to factor this? HERE IS MY CODE: import { shallow, mount, render } from 'enzyme'; import App from '../client/src

Simulate vs props - On Change event using Jest and Enzyme

主宰稳场 提交于 2019-12-12 16:31:42
问题 I am trying to run test for multiple onChange events. The test right now passes with the following code but does not affect its COVERAGE, means incorrect wrapper.find('Datasubjects').props().onChange({City:{target:{value:'test'}}}) But it fails if I use the following: wrapper.find('Datasubjects').find('input[id="city-label-id"]').simulate('change',{City:{target: {value:'test'}}} ) Here is part of Render(), showing the onChange event that I am trying to test: <Modal isOpen={this.state

How to traverse a shallow component nested in ThemeProvider HOC?

痞子三分冷 提交于 2019-12-12 14:58:08
问题 Following up the issue on Github, I have a component Comp that when exported, is wrapped with injectSheet from reactjss . Please see the setup on codesandbox . In a unit test, I'd like to assert that that component contains <a> , which it does (see codesandbox), but the test fails regardless: describe("<Comp /> component", () => { const wrapper = shallow(<Comp />); it("should render a <a>", () => { expect(wrapper.find('a')).to.have.length(1); }); }); I get Error: [undefined] Please use

How to pass data as context in Jest?

南楼画角 提交于 2019-12-12 14:40:11
问题 I am trying to pass the context in an Enzyme test using Jest, as shown in the Airbnb doc, but the context is returning undefined . I am not sure what I am doing wrong here. App.js class App extends Component{ componentWillMount(){ console.log("Context in App", this.context) // getting undefined when running test case } render(){ return( <div> Sample Application </div> ) } } export default App; App.test.js import React from 'react'; import { shallow } from 'enzyme'; import App from './App';