mardi 1 septembre 2020

How to use multiply times async function in mocha tests

I would like to use multiply times async foo function in mocha tests and try to do it like this:

describe('This test', () => {
    const foo = async () => {
        const wrapper = mount(Component);
        const button = wrapper.find('button');
        button.simulate('click');
        wrapper.update();

        await new Promise(res => setTimeout(() => {
          res('');
        }, 0));
        
        wrapper.update();

        return wrapper;
    };

    it('should pass 1', () => {
        const wrapper = foo();
        console.log(wrapper.debug());
    });

    it('should pass 2', () => {
        const wrapper = foo();
        console.log(wrapper.debug());
    });
  });

But then output is TypeError: wrapper.debug is not a function

This works fine without async await.

Can you help resolve it?

Aucun commentaire:

Enregistrer un commentaire