Skip to content

Instantly share code, notes, and snippets.

@yury-sannikov
Created August 10, 2017 20:18
Show Gist options
  • Save yury-sannikov/8ecc209f6f46c245d79edd085f6d3ca4 to your computer and use it in GitHub Desktop.
Save yury-sannikov/8ecc209f6f46c245d79edd085f6d3ca4 to your computer and use it in GitHub Desktop.
poolForChanges(so) {
// Prepare environment
const component = componentFactory({});
const callback = sinon.spy();
// Invoke component helper method
helper.poolForChanges(component, callback);
// helper method should call another helper method.
// It's second parameter has a callback we are going to test
expect(helper.pullSummary).to.have.been.called;
const [{args: [,pullTicketSummaryCallback]}] = helper.pullSummary.getCalls();
// Invoke pullSummary's callback we extracted from stubbed pullSummary helper method
pullSummaryCallback(so);
// An outer callback should not called because inside pullSummaryCallback helper method has setTimeout() call
expect(callback).not.to.have.been.called;
this.clock.tick(751);
// Outer callback will be called after a timeout in a synchronous manner
expect(callback).to.have.been.called;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment