Skip to content

Instantly share code, notes, and snippets.

@th3james
Last active August 29, 2015 13:56
Show Gist options
  • Save th3james/8827009 to your computer and use it in GitHub Desktop.
Save th3james/8827009 to your computer and use it in GitHub Desktop.
DOM event listener test
suite("PickUserView");
test('when clicking the close button, the view gets closed', function() {
var view, viewCloseSpy;
// The function we expect to be called on close
viewCloseSpy = sinon.spy(ChooseUserView.prototype, 'close');
view = new ChooseUserView();
view.render();
// Trigger the click event on the DOM element
view.$el.find('.close').trigger('click');
// Stop spying
viewCloseSpy.restore();
assert.ok(
viewCloseSpy.calledOnce,
"Expected viewCloseSpy to be called once but was called " + viewCloseSpy.callCount + " times"
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment