mercredi 5 juillet 2017

How to test nested mocked functions

How can I write tests on mocked functions inside a mocked function? I want to test that my publish mocked function is called once.

jest.mock('amqplib', () => ({
  connect: jest.fn(() => Promise.resolve({
    createChannel: jest.fn(() => Promise.resolve({
      assertExchange: jest.fn(),
      publish: jest.fn(),
    })),
    close: jest.fn(),
  })),
}));

Aucun commentaire:

Enregistrer un commentaire