开玩笑测试一个组件包含导入的功能

时间:2019-02-25 18:52:20

标签: reactjs testing jestjs

我正在使用Jest测试组件,这是我要测试的组件:

<div className={'b-popover b-hover b-bottom'}>
    <div className={'b-content b-pull-left'}>
        <div className={'b-body bui-text-small'}>
            <FormattedMessage id={getStringByKey(GROUP_ASSIGNMENT_STRINGS, 'exceeding-fifty-groups-warning-tooltip-id')} defaultMessage={getStringByKey(GROUP_ASSIGNMENT_STRINGS, 'exceeding-fifty-groups-warning-tooltip')}/>
        </div>
    </div>
</div>

这是我的测试代码:

describe('When <GroupRow />', () => {

        it('it should structure the component correctly when input is disabled', () => {
            const props = {inputSectionType: ROW_INPUT_TYPE_DISABLED};
            const content = render(<GroupRow inputSectionType={props.inputSectionType}/>);
            expect(content).toMatchSnapshot();
        });
});

FormattedMessage内部,这是一个函数getStringByKey(),它是从../../../constants导入的。 getStringByKey()的功能目前并不重要。但是当我运行测试套件时,出现错误:

TypeError: (0 , _constants.getStringByKey) is not a function

那么我该如何模拟该功能?谢谢。

0 个答案:

没有答案
相关问题