use*_*191 7 unit-testing reactjs jestjs enzyme
尝试为以下内容运行单元测试:使用 REACT JS - 这里的 Jest 和酶是代码的一部分:
componentDidMount () {
let requestSettings = this.props.getViewRequestSettings()
let linkerDefinition = requestSettings.catalog[0].resolvedtemplate[0]
if(linkerDefinition.includes('Universal')){
let functionName =
linkerDefinition.substr(0,linkerDefinition.indexOf('('));
Run Code Online (Sandbox Code Playgroud)
单元测试文件:我设置了所有道具,但不确定它是否正确
类型错误:specificMockImpl.apply 不是函数
调用道具:
// jest mock functions (mocks this.props.func)
const getViewRequestSettings = jest.fn([{requestSettings :{catalog:[0],
resolvedtemplate:[0]}}]);
// defining this.props
const baseProps = {
getViewRequestSettings,
Run Code Online (Sandbox Code Playgroud)
错误:const getViewRequestSettings = jest.fn([{requestSettings :{catalog:[0],resolutiontemplate:[0]}}]); 不确定如何正确设置
Shu*_*tri 12
在代码中调用函数时,将参数传递给 jest.fn 不会返回该值。模拟实现或模拟返回值
const extractDataFromXML = jest.fn(() => ([{ applyodata:[0], liquidoption:[0]}]));
Run Code Online (Sandbox Code Playgroud)
const extractDataFromXML = jest.fn();
extractDataFromXML.mockReturnValue([{ applyodata:[0], liquidoption:[0]}]);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8119 次 |
| 最近记录: |