我对测试数组有问题。请检查截图 https://ibb.co/0Dx26vf
beforeEach(() => {
dashboard.find('.review-number').simulate('click')
})
it('Call the `addFeedback` callback', () => {
expect(mockRemove).toHaveBeenCalledWith('1', '1')
})
})
这里是组件:
<Row>
{projects && projects.map((project, i) => {
return (
<Col sm={4} key={i}>
<div className='mainBoxItem'>
<Link to={'/project/' + project.id} >
<div className='overflow-hidden'>
<img src={project.userImage} alt='Car' />
</div>
<h3>{project.carType} {project.carModel}</h3>
</Link>
<div className='flex'>
<p>{project.authorFirstName}</p>
<em>{moment(project.createdAt.toDate()).calendar()}</em>
</div>
<span className='car-price'>{project.carPrice} {project.Currency} / <em>Per Day</em></span>
<span className='review-number' onClick={() => this.addFeedback(project.id, project.feedback)}>+1 ({project.feedback})</span>
</div>
</Col>
)
})}
</Row>
</Container>```
[1]: https://i.stack.imgur.com/LLSxx.png
答案 0 :(得分:0)
我刚刚解决了这个问题
在这里您可以检查我的考试
import Adapter from 'enzyme-adapter-react-16'
import { shallow, configure } from 'enzyme'
import { Dashboard } from './index'
configure({ adapter: new Adapter() });
describe('Dashboard', () => {
const mockRemove = jest.fn()
const props = { addFeedback: mockRemove, projects: [] }
const dashboard = shallow(<Dashboard {...props} />)
console.log(dashboard.debug())
it('render Dashboard', () => {
expect(dashboard).toMatchSnapshot()
})
describe('Add feedback on click', () => {
beforeEach(() => {
dashboard.find('.review-number').simulate('click')
it('Call the `addFeedback` callback', () => {
expect(mockRemove).toHaveBeenCalled()
})
})
})
})
您需要将<Dashboard {...props} />
道具阵列发送到您的组件