在函数中反应测试callOnce函数

时间:2018-09-12 13:15:40

标签: reactjs mocha sinon

能否请您告诉我如何进行函数调用存根?

MainComponent:

foo = (arrFav, symbol) => {
        const { arrowResourcesInfo } = this.props;

        const isFavoriteChecked = this.checkFavoriteElement(arrFav, symbol);
        const objectNMT = this.createNMTObjectFavorites([...arrFav], new Date().getTime(), symbol);

        Wrapper(this.timeFrame, this.symbolData, this.showFullCurrencyPair, this.dialogOpenDeals, this.openDetailInfo, this.getFullSymbolName, this.selectorIcon, isFavoriteChecked, this.changeFavoritesTechAnalysis, this.clearDataFromTechDetailWindow, objectNMT, arrowResourcesInfo, this.createDirectionImage);
    };

和测试用例:

const instance = shallow(<MainComponent { ...props }/>).instance();
            instance.state.activeCategory = 'favorites';
            const spy = sandbox.spy(instance, 'foo');
            instance.foo(favorites, 'param');
            sandbox.assert.calledOnce(spy);

测试是错误的,因为包装器想要在他的体内放置参数。但是我想把他的话存根。

0 个答案:

没有答案
相关问题