lundi 25 février 2019

Jest test a component contains imported functions

I'm testing a component using Jest, here is the component I want to test:

<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>

And here is my test code:

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();
        });
});

Inside FormattedMessage, here is a function getStringByKey(), and it is imported from ../../../constants. The functionality of getStringByKey() is not important at this time. But when I ran the test suite, I get the error :

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

So how can I mock this function? Thanks.

Aucun commentaire:

Enregistrer un commentaire