Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocha Async Test (done) #25

Closed
Hosar opened this issue Feb 1, 2017 · 5 comments
Closed

Mocha Async Test (done) #25

Hosar opened this issue Feb 1, 2017 · 5 comments

Comments

@Hosar
Copy link

Hosar commented Feb 1, 2017

Hi, how can I test async actions? It's possible?

I wanted to have my enzyme tests and my redux test on one single place.

return store.dispatch(actions.asyncAction(value)).then((res) => {
  expect(res).to.be.true;
});

But it always returns true even if res is false. Then tried with done, and throw this error: TypeError: done is not a function

it('some test', (done) => {
    return store.dispatch(actions.asyncAction(value)).then((res) => {
        expect(res).to.be.true;
        done();
   });
});

It's possible?

Thanks in advance.

@mthuret
Copy link
Owner

mthuret commented Feb 3, 2017

Hi @Hosar,

I believe it's currently not possible. When executing the test with storybook, you are using the it implementation that I've done for this addon. That's why you don't have the done function.

We are currently investigating on a way to execute the tests server side so that you can use fully jest. #17 (bottom)

Also, I'm curious about the motivation behind 'enzyme tests and my redux test'. Is that because you find is more convenient, or you also want to display redux test on storybook?

@Hosar
Copy link
Author

Hosar commented Feb 7, 2017

Hi @mthuret first thank for this cool plugin, I really like to work with storybook.

What I tried to do was to test the behavior of my components. And it's actually working.
e.g.

specs(() => describe('Vendor Products', () => {
         it('should add to favorites', () => {
                const product = fakeProduct;

                const addToFavorites = () => {
                    store.dispatch({
                        type: constants.actions.ADD_TO_FAVORITES,
                        payload: product
                    });
                };

                const wrapper = mount(
                    <Favorites addToFavorites={addToFavorites} />
                );

                store.subscribe(() => {
                    const { productsByVendor } = store.getState();
                    expect(productsByVendor.lastAddedToFavorites).to.equal(product.id);
                });

                wrapper.find('button').simulate('click');
            });
}));

So now I can test UI features (enzyme) and expected behavior (redux). And there is no need for done as I was expecting.

@mthuret
Copy link
Owner

mthuret commented Feb 8, 2017

Hey @Hosar, that's nice you find a way to test your redux action along with your component :D

Do you think it misses an entry in the documentation for explaining those kind of things?

@therealparmesh
Copy link
Contributor

therealparmesh commented Jun 14, 2017

I am attempting to address this issue with #47!

@therealparmesh
Copy link
Contributor

Can we close this issue as per #48?

@mthuret mthuret closed this as completed Jun 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants