Created
July 12, 2017 02:14
-
-
Save khaosdoctor/42c317d577a30b44c02b97653d9b9137 to your computer and use it in GitHub Desktop.
Mock Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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