87 questions
0
votes
1
answer
440
views
What's the error in the code . Line 51:8: Parsing error: Unexpected token, expected "{"
I am learning reactjs and I am getting parsing error in last line export App3; Please go through the below code guys and let me know what's the error(What's the error in the code . Line 51:8: Parsing ...
1
vote
2
answers
50
views
I am learning react and my code is working fine but how can i declare currDate single time to use it globally to use in useState
How can I declare currDate globally to use it in useState. The following code works just fine but wish to make it more efficient.
Is there any better way to shorten the code?
import React, { useState }...
1
vote
1
answer
210
views
Testing functions directly in Functional component
Suppose we have a functional component as below.
const Test: React.FC = () => {
const isItemSelected = () => { console.log('Hi); };
return (
<div> </div>
);
};
And I want ...
2
votes
1
answer
2k
views
testing nested component callback in react
given a Foo (root) component that renders Baz nested component, where Baz has a property named onOperationDone which accepts a callback.
class Foo extends React.Component {
constructor(props) {
...
3
votes
2
answers
5k
views
how to test combineReducers with jest
I am trying to test combineReducers but getting following error.
TypeError: _testReducer.testReducer.test11 is not a function
Following is the reducer
// testReducer.js
import { combineReducers } ...
15
votes
1
answer
6k
views
what is adapter in enzyme
Any documentation on what's the purpose of adapter in enzyme testing library.
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });...
1
vote
1
answer
2k
views
React Test Utils vs Selenium WebDriver
We have used React JS for front end and we need to write end to end tests. After researching online, we came across 2 options :
1. Selenium WebDriver
2. React Test Utils (https://reactjs.org/docs/...
1
vote
1
answer
13k
views
React testing button property disable
I cannot write correct test case for button property disable. I use TestUtils from react-addons-test-utils.
I have very simple component:
const propTypes = {
disabled: PropTypes.func.isRequired
...
0
votes
1
answer
359
views
How Can I Fix this Error with Karma & React 16.2.0?
I have this Karma configuration (with React 16.2.0):
const isArray = require('lodash/lang/isArray');
const merge = require('lodash/object/merge');
const path = require('path');
const webpack = ...
1
vote
1
answer
1k
views
reactjs / jest : unable to populate react-apollo component with data using MockedProvider?
I have written simple react-apollo component which uses graphql query to retrieve data from schema. On execution component works fine but, when I am writing test case for this component using jest ...
0
votes
0
answers
164
views
Unit test case for React Component using enzyme
I am working on reactjs 5.X version. I am writing UT with enzyme. Below is my reusable component with prop arguments. Not able to find the div tags inside of the const component.Can you help me how to ...
2
votes
0
answers
296
views
React test-utils scryRenderedDOMComponentsWith* not traversing nested components
Having an issue with testing components. I have a Voting component that renders a Vote component, and the Vote component renders two <button> tags. Using mocha+chai and react-dom/test-utils ...
0
votes
0
answers
65
views
translate dom in react for testing purposes
Hi guys I have a question for anybody that can help. Is there any helper function to translate a document.body to React structure and access it like getElementBy.. ? So I can access the individual ...
4
votes
1
answer
677
views
ReactTestUtils Simulate.Change parameter type SyntheticEventData error
I have this code below written in typescript which use ReactTestUtils from "react-dom/test-utils".
let nameInput = TestUtilsExtended.findRenderedDOMComponentWithTag(root, "input");
TestUtilsExtended....
0
votes
1
answer
51
views
Use react's testutils with jquery elements
I am trying to test a react page. Using .trigger("input", {which: 65}) doesn't seem to invoke the SyntheticEvent. So I was wondering if was possible to combine jQuery and .simulate of the testUtils ...
3
votes
2
answers
708
views
mock a function which is used in another function
I am writing test for my async action in react redux, for sake of addressing just the issue I simplified the code here. Here is my action function:
export function updateUserAuthenticationStatus(){
...
0
votes
1
answer
1k
views
I get TypeError: Cannot read property 'then' of undefined when I try to test async action
I have a problem testing my async action in reactjs.
Here is my code:
export function fillStoryBoard(snippetsLink, channel, uniqueStoryObj, isUniqueStorySearch) {
return function(dispatch){
...
1
vote
1
answer
2k
views
Very high memory/cpu usage while testing React components with Karma in Chrome
Currently in my project I'm using Karma and Mocha, with React Test-Utils to test my react components.
I currently have around 1200 tests, most of which are for my library of react components.
When ...
0
votes
1
answer
795
views
React Test : Finding Component within Component
I can find a component at the first 'finder' in the code below
var myComponent = ReactTestUtils.findRenderedDOMComponentWithClass(myDiv, 'myComponent')
If I then use the returned Component object and ...
3
votes
1
answer
2k
views
React.js and Jasmine Spies
Using basic test-utils and jasmine for unit testing.
How do you spy on a function inside a react component?
test.js:
class Test extends React.Component {
handleClick() {
// Do something
}
...
1
vote
1
answer
1k
views
react component test cannot find text
I am writing a test case for a particular component I created. The component is here
import React, { PropTypes } from 'react';
import moment from 'moment';
const RouteHeader = ({ activeTab, ...
0
votes
1
answer
1k
views
Reactjs Test api call
I want to develop using Reactjs, I made an App where I call an API (https://jsonplaceholder.typicode.com/users), also I made a test for this call and I couldn't call this API.
I made a little WebApi ...
50
votes
17
answers
90k
views
Testing React Select component
https://github.com/JedWatson/react-select
I would like to use React-Select react component, but I need to add tests.
I've tried several options I found with google, but nothing seems to work. I have ...
1
vote
3
answers
132
views
React component test keeps failing
I keep getting this error when testing my TodoList component:
debug.html:38
Invariant Violation:
Element type is invalid:
expected a string (for built-in components) or a class/function (for ...
1
vote
1
answer
1k
views
Fake server response body should be string, but was undefined
I am trying to do unit tests at react components with mocha, chai and sinon.
My first test worked, it is simple checking if component exists and if props are used correctly.
Now I having trouble ...
1
vote
0
answers
838
views
Testing react components componentDidMount, how do I render into a new document after each test?
Tests run, but they are rendering into the same document. On componentDidMount Style component appends CSS text to a style element in head with the class .reactive-style (know this is unorthodox and ...
31
votes
4
answers
38k
views
Why React event handler is not called on dispatchEvent?
Consider the following input element in a React component:
<input onChange={() => console.log('onChange')} ... />
While testing the React component, I'm emulating user changing the input ...
2
votes
1
answer
2k
views
React testing: Change value of input field
I can not set the value of input field. What am I doing wrong?
If any more information is needed, please tell me so. Thank you.
describe('SignUpComp', () => {
let signUpComp, node;
...
6
votes
2
answers
4k
views
Test window keydown event in Reactjs
The component I am writing needs to change its behaviour depending on whether ctrl is pressed or not.
I use a window.onkeydown event but Simulate from React Test Utils doesn't allow me to dispatch ...
4
votes
0
answers
331
views
ReactJS Component testing with mocked http calls
I've taken a ReactJS component (rendering the latest gist URL for a given user) from the React docs, and was wondering what is the best way to unit test such a component :
The goals are
Test in ...
18
votes
3
answers
25k
views
Change element size using Jest
I have following code in my component
var rect = ReactDOM.findDOMNode(this).getBoundingClientRect();
I use d3js and render graph in the component. But when I run test there are any svg tags. I assume ...
0
votes
1
answer
3k
views
TestUtils.Simulate.change doesn't update value of input
I make a very easy component to test the TestUtils.Simulate reactJS method. But I don't know why this method doesn't update the value of my component. I guess I wrote my code on the wrong way.
This ...
2
votes
1
answer
5k
views
react testUtils simulate click on a radio button not triggering onchange
For testing Im using JSDom, mocha, chai and ReactTestUtils.
One of my component got three radio button, that when a change is detected (onChange) will run a function.
Everything works in manual ...
0
votes
1
answer
503
views
ReactTestUtils findRenderedComponentWithType throwing error not detecting by chai?
Im using findRenderedComponentWithType to make sure there is a error, and Im using chai's assert.throws, but it is not working.
first of all:
TestUtils.findRenderedComponentWithType documentation:
...
0
votes
1
answer
117
views
Writing React TestUtils test case for function without parameters
So I have a function to remove all tabbing from a particular page. There is a variable declared in this function that does the work. I need to pass dummy value to this variable so that the value will ...
23
votes
1
answer
4k
views
Mocking file input in React TestUtils
I have a component with the following render function:-
render: function() {
<input
type="file"
name: this.props.name,
className={this.props.className}
onChange={this....
1
vote
1
answer
116
views
Error 'h1.findDOMNode is not a function' when running a Karma test
I am trying to write a simple test. I have Karma as the test runner and Mocha as the framework.
Each time I run the test, it fails with the error...
TypeError: h1.findDOMNode is not a function
Here'...
2
votes
1
answer
293
views
How to set HTML5 file type input with ReactTestUtils
I have an HTML5 file type input in a React form similar to the following
<input type='file' ref='fileInput' onChange={this.onChange} multiple/>
and once a file is uploaded this.onChange ...
0
votes
1
answer
417
views
React Test Utils - Spy not called when a simulated click is performed -
I'm trying to simulate a click on a dom element in a react component and assert that a spy is called based on this. Here's the relevant part of the test (using karma, mocha, chai, sinon but I'm fairly ...
4
votes
2
answers
5k
views
How to test a React component that uses context like in react-router 2.0 with Jest 0.8.x
I had this problem in the past while using older versions of react-router which I solved using: stubRouterContext + a hacky way to access the component instance (using refs: https://github.com/reactjs/...
1
vote
1
answer
4k
views
Testing React component onClick event with multiple actions in it
Can't figure it out how to test onClick function with multiple actions in it.
onButtonClick = function(action){
this.props.otherAction();
action();
}
...
<Button bsStyle="success" bsSize="...
10
votes
1
answer
20k
views
React testing component prop change with enzyme
I am modifying an example found here:
https://github.com/airbnb/enzyme/blob/master/docs/api/ReactWrapper/setProps.md
class Foo extends React.Component {
render() {
return (
&...
0
votes
1
answer
577
views
React/Jasmine/Karma/Phantom Unit Test: findDOMNode and renderIntoDocument not working as expected
I'm trying to write a simple unit test and can't seem to figure it out. I want to test a bootstrap modal to ensure it displays the correct contents when I pass certain object properties to it. Here's ...
1
vote
1
answer
407
views
React 0.14.5 Composite Components and Children's public methods
I'm trying to test the public method on a React Class. This is easy enough as you can see in the first spec, but if I need to provide context, the component needs to be wrapped in a composite ...
0
votes
0
answers
436
views
ReactJS TestUtils Garbage Collection
For ReactJS's test utility class : TestUtils, how do they handle garbage collection?
There are no methods that de-allocate or destroy a React Module that was created beforehand in renderIntoDocument ...
11
votes
2
answers
3k
views
Error: Invariant Violation: findAllInRenderedTree(...): instance must be a composite component
While writing the test case in JEST for React file I am getting this error. Following is my sample code:
search_basr_test.js
jest.autoMockOff();
global.React = require('react/addons');
jest.setMock('...
4
votes
5
answers
19k
views
Unit testing React component using Material UI Dialog
I am currently writing unit tests for my React + MaterialUi application.
In my application I have a Dialog. I want to make sure depending on what button pressed on the dialog:
<FlatButton
label=...
1
vote
1
answer
677
views
ReactTestUtils.renderIntoDocument a component with children - children seem to "not render in DOM"
I render a component in my test like so:
component = TestUtils.renderIntoDocument(
<SlidingContainer {...props}>
<div style={divStyle}>foo</div>
<div style={divStyle}&...
5
votes
1
answer
3k
views
Jest issue - ReactElement.js: Failed to get mock metadata
I've a very simple test
/** @jsx React.DOM */
var store = require('../simpleStore');
var TestUtils = require('react/addons').addons.TestUtils;
describe("my tests",function(){
it('simple test',...
0
votes
1
answer
1k
views
Sinon.stub getting called in test, but expect to be called statement fails
I have a stateless react component that has an onClick method that I'm trying to test is getting called.
The way I'm doing it is to set a prop with a default value pointing towards the method that ...