尝试对以下各项进行单元测试:使用REACT JS-开玩笑和酵素 这是代码的一部分:
componentDidMount () {
let requestSettings = this.props.getViewRequestSettings()
let linkerDefinition = requestSettings.catalog[0].resolvedtemplate[0]
if(linkerDefinition.includes('Universal')){
let functionName =
linkerDefinition.substr(0,linkerDefinition.indexOf('('));
单元测试文件:我已经设置了所有道具,但不确定其是否正确
TypeError:specificMockImpl.apply不是函数
调用道具:
// jest mock functions (mocks this.props.func)
const getViewRequestSettings = jest.fn([{requestSettings :{catalog:[0],
resolvedtemplate:[0]}}]);
// defining this.props
const baseProps = {
getViewRequestSettings,
错误:const getViewRequestSettings = jest.fn([{requestSettings:{catalog:[0], resolvetemplate:[0]}}]);不确定如何正确设置
答案 0 :(得分:1)
在代码中调用函数时,将参数传递给jest.fn不会返回该值。模拟实现或模拟返回值
const extractDataFromXML = jest.fn(() => ([{ applyodata:[0], liquidoption:[0]}]));
const extractDataFromXML = jest.fn();
extractDataFromXML.mockReturnValue([{ applyodata:[0], liquidoption:[0]}]);