Skip to content

Instantly share code, notes, and snippets.

@khaosdoctor
Created July 12, 2017 02:14
Show Gist options
  • Save khaosdoctor/42c317d577a30b44c02b97653d9b9137 to your computer and use it in GitHub Desktop.
Save khaosdoctor/42c317d577a30b44c02b97653d9b9137 to your computer and use it in GitHub Desktop.
Mock Example
describe('Exemplo de Mock', (assert) => {
var myAPI = { method: function () {} };
var spy = sinon.spy();
var mock = sinon.mock(myAPI);
mock.expects("método").once().throws(); // Substituímos o "método" por outra função previsível
PubSub.subscribe("message", myAPI.method);
PubSub.subscribe("message", spy);
PubSub.publishSync("message", undefined);
mock.verify(); // Esta opção verifica se o mock está de acordo com as regras
assert(spy.calledOnce);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment