score:1
Accepted answer
tests/index.tsx
import * as react from 'react'
import { expect as expect1 } from 'chai';
import indexpage from '../pages/index'
import {/*mount,*/ shallow} from 'enzyme'
const setup1 = (data) => {
return shallow(<indexpage {...data} />);
}
let wrapper;
describe('props check', () => {
beforeeach(() => {
wrapper = setup1(allpostsdata={[]});
});
it('should render an `.icon-stars`', () => {
expect1(wrapper.find('.icon-stars')).to.have.length(1);
});
});
you have to pass props inside the testing component & use
import * as react from 'react'
in pages/index.tsx for rendering react components
Source: stackoverflow.com
Related Query
- Is it Possible to use Enzyme testing with Next js (SSR)?
- When testing a React component with Enzyme is it better to use simulate or to call the method directly on the instance()?
- Is it possible to use Jest with multiple presets at the same time?
- Nested components testing with Enzyme inside of React & Redux
- Is it possible to use react-datepicker with react hooks forms?
- Is it possible to use material-ui button navigation with react-router?
- Is it possible to use Material UI library with React Native?
- Accessing the State of a Functional Component with React Hooks when Testing with Enzyme
- Testing React portals with enzyme
- Testing with React's Jest and Enzyme when simulated clicks call a function that calls a promise
- Testing with React's Jest and Enzyme when async componentDidMount
- Storybook JS Interaction Testing with Enzyme - State Changes being Overidden
- Testing functions inside stateless React component with Enzyme
- Testing react-router v4 with Jest and Enzyme
- Is it possible to use Harmony (ES6) with JSXTransformer.js?
- How to use useRef hook to select next TextInput after pressing next keyboard button with redux-form
- React testing component prop change with enzyme
- Testing debounced function in React component with Jest and Enzyme
- _this.store.getState is not a function when testing react component with enzyme and mocha
- Testing react-intl components with enzyme
- Is it possible to use GraphQL with an offline mobile database like SQLite or PouchDB
- Set URL params while testing with Jest & Enzyme
- Testing the `React.createRef` api with Enzyme
- Testing recompose's HOC with enzyme
- Is it possible to use decorators with create-react-app?
- Testing component with react-router v4, Jest and Enzyme
- Enzyme render fails when importing image with webpack while testing with Jest
- Testing React Component className with enzyme
- How to test Material-UI's Responsive UI (e.g. Hidden, Grid, Breakpoints) in React with Enzyme or React Testing Library
- Testing react router v4 with jest enzyme
More Query from same tag
- Failed to compile: <function name> is not defined no-undef
- Jest function call for functional component gives error on stimulate click
- Nginx - try_files: How to set up a remote file (url)?
- Pass prop from parent to child in React
- MP4 file not loading on React / Rails app
- How to fire when click li element (react-paginate)
- Keeping updated objects relations in React state
- How to create a custom hook to post to an API and store result?
- How do I manage mysql query errors from express in a React form?
- How to submit a React form on <select> element change, but keep validation for other inputs in the form?
- What can be the best way for automatic deployment of my application on AWS?
- Opening a sub-page in react
- React TypeError: undefined onSubmit
- With mapStateToProps, how to find and set a specific record?
- How to achieve infinite scrolling in React with variable height elements?
- Count time between 2 dates for multiple forms using reactjs
- make a wrapper function around map in react
- Why am I getting an error with cors in ExpressJS in one case, but not the other?
- Declare arguments with interface on typescript react hook
- Using react2angular, react isn't recognized, no erros
- Can't get CORS working in ReactJS Application with nginx
- Using window.location when registering a user account in React
- Fetch call in ReactJS to PHP file returning undefined
- TypeError: Cannot read property 'map' of undefined, How do i rectify this?
- In React-Router-Dom how do I go to another page while also going to an id
- React router redirect if not signed in
- If 'React' is the default export from 'react', Why can't we use some other name instead of 'React'
- ReactJS - Using setState with firebase listen
- Cannot read property 'state' of undefined in one place and in another it can read
- How to use functions in react-avatar-editor