vendredi 2 mars 2018

Stub classList functions add, remove with Enzyme

<code>enter image description here</code>

    global.window.document.getElementsByClassName = sinon.stub();
    describe('Shallow Render', () => {
    let wrapper;

    beforeEach(() => {
        global.window.document.getElementsByClassName.returns({ className: '' });
        wrapper = shallow(
            <SignInSlider
                {...props}
                />,
            );
    });

    afterEach(() => {
        global.window.document.getElementsByClassName.reset();
        wrapper.unmount();
    });

    it('it rendered successfully', () => {
        expect(wrapper.find('SlidePanel')).to.exists;
        expect(wrapper.find('LoginWrapper')).to.exists;
        wrapper.find('LoginWrapper').prop('onClickOfCreateAccountButton')();
        wrapper.find('LoginWrapper').prop('onClickPasswordReset')();
    });
   });

My function:

    onClickOfCreateAccountButton() {
    const el = document.getElementsByClassName('SignInSlider-loginSlider')[0];
    const el1 = document.getElementsByClassName('SignInSlider-createAccountSlider')[0];

    el.classList.add('SignInSlider-animate-show');
    el.classList.remove('SignInSlider-animate-hide');
    setTimeout(() => {
        this.props.signInSliderActions.openCreateAccountPage();
        el1.classList.add('SignInSlider-animate-show');
    }, 5);
}

How do I stub the classList?

Aucun commentaire:

Enregistrer un commentaire