Monday, 8 May 2017

Sinon expected spy to have been called with arguments

I am writing a mocha test to test what has been called with my dispatch method of 'TRACK'. However I receive the following error:

 AssertionError: expected spy to have been called with arguments INITIAL_COMMENTARY, [{ eventId: "5672" }]
  at Context.<anonymous> (test.js:99:39)   



it("should update the store when there was commentary returned", () => {
        const response = createResponse([
          {eventId: '5672'},
        ]);
        request.yields(null, response, response.body);

        intercept('TRACK', [
          bet(trackableSelection({eventId: 5672})),
        ]);

        expect(request).to.have.been.calledWith({
          url: '/foo/commentary?eventId=5672',
          json: true,
        });

        expect(dispatch).to.have.been.calledWith('INITIAL_COMMENTARY', response.body.data);
      });
    });

The 'INITIAL_COMMENTARY' in the stores is the following:

  INITIAL_COMMENTARY(state, commentary) {
    logger.debug("Storing initial commentary for events");
    return state.mergeIn(['commentary'], parseCommentary(commentary));
  },

And just incase parseCommentary function is the following:

export default function parseEventCommentary(commentary) {
  return fromJS(
    commentary.reduce((events, event) => {
      events[event.eventId] = parseSingleCommentary(event);
      return events;
    }, {})
  );
}



via jord

No comments:

Post a Comment