Skip to content

Instantly share code, notes, and snippets.

@JoshuaKGoldberg
Created January 31, 2017 20:16
Show Gist options
  • Save JoshuaKGoldberg/59aeb2ab8dc370cbc0474b86d3a1e4c7 to your computer and use it in GitHub Desktop.
Save JoshuaKGoldberg/59aeb2ab8dc370cbc0474b86d3a1e4c7 to your computer and use it in GitHub Desktop.
Sinon stub with a return value
attempt_CallsOnFail_IfMyApiFails() {
// Arrange
const onFail = sinon.stub();
const onSucceed = sinon.stub();
const externalApi = sinon.stub().returns(false);
const actor = new Actor({ externalApi, onFail, onSucceed });
// Act
actor.attempt(); // internally calls externalApi
// Assert
UTF.Assert.True("onFail should have been called", onFail.calledOnce);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment