Skip to content

Instantly share code, notes, and snippets.

@goldbergyoni
Created October 29, 2019 15:58
Show Gist options
  • Select an option

  • Save goldbergyoni/5508b12233fe327ed3564a2956a2e78f to your computer and use it in GitHub Desktop.

Select an option

Save goldbergyoni/5508b12233fe327ed3564a2956a2e78f to your computer and use it in GitHub Desktop.
grey-box-component-test
test('When an order error occurs, an email is sent to the admin', () => {
//Arrange
sinon.stub(dataAccessCode , 'saveOrder').throws(new Error('DB save failed'));
const spyOnMailer = sinon.spy(mailer , "sendEmail");
const orderToAdd = {userId: 1, productId: 2, mode: 'approved'};
//Act
const receivedResponse = await request(expressApp).post("/order").send(orderToAdd);
//Assert
expect(spyOnMailer.calledWith(configurationService.adminEmail)).toBe(true);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment