Git Product home page Git Product logo

Comments (6)

LouisBarranqueiro avatar LouisBarranqueiro commented on July 30, 2024

Hey @Arturszott, what the benefit of this implementation?

from reapop.

Arturszott avatar Arturszott commented on July 30, 2024

When I'm testing redux actions I can now check if dispatch was called with the object, which was not available when we were dealing with thunk. function instance !== function instance.

Plain objects are iteratable so I can write:

dispatch(createNotification({ status: 'error', title: 'Errrrrr', message: 'something went wrong' }));

expect(dispatch).to.have.been.calledWith({
   type: '__SEND_NOTIFICATION__',
   payload: { status: 'error', title: 'Errrrrr', message: 'something went wrong' }
})

from reapop.

LouisBarranqueiro avatar LouisBarranqueiro commented on July 30, 2024

I don't understand the benefit of this test, since we already test each action creators ?

from reapop.

Arturszott avatar Arturszott commented on July 30, 2024

Sure. Action creators are tested by itself, but I want to make sure in my action file, that I'm passing the right set of data to it. I can't do this when actionCreator is returning a thunk, because parameters are held inside within the closure.

from reapop.

LouisBarranqueiro avatar LouisBarranqueiro commented on July 30, 2024

I'm sorry man but I still don't understand why do you want to check its parameter since we test each actions creators by checking the result in the store. Eg (source) :

it('should create an action to add a notification ' +
        '(add `id` property and convert status)', () => {
        notification.id = null;
        // we remove the image, otherwise `treatNotification()` helper will update
        // status of notification
        notification.image = null;
        // here we simulate an HTTP success status code (200 = OK)
        notification.status = 200;
        const notificationAdded = store.dispatch(addNotification(notification));
        const expectedAction = [{
          type: types.ADD_NOTIFICATION,
          payload: Object.assign({}, notification, {
            id: notificationAdded.id,
            status: SUCCESS_STATUS
          })
        }];
        expect(store.getActions()).toEqual(expectedAction);
      });

that's why these tests are enough to be sure that if we add a notification { status: 'error', title: 'Errrrrr', message: 'something went wrong' } with addNotification (async action creator), the store will contains an action {type: 'ADD_NOTIFICATION', payload: { id:1231231234, status: 'error', title: 'Errrrrr', message: 'something went wrong' }.

from reapop.

Arturszott avatar Arturszott commented on July 30, 2024

Hmm. Okay, now I get your way of thinking.

For me this kind of test is introducing too much boilerplate into the testing code. That was the reason why I decided to create this middleware. I like my test with the least configuration possible. For testing with store is has to be set first and configured.

Thanks for reviewing my idea anyway. I wanted to share the idea of the code, that actually works for me, but what works for me must not necessary work for you!

from reapop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.