Created
October 18, 2013 17:12
-
-
Save hauntedhost/7044683 to your computer and use it in GitHub Desktop.
jasmine spy cheatsheet
This file contains 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
//= require jquery | |
//= require track-events | |
describe('TrackEvents', function () { | |
beforeEach(function () { | |
loadFixtures('track-events_fixture'); | |
}); | |
it('triggers a Test.fire', function() { | |
Test = function () { } | |
Test.fire = function () { } | |
spyOn(Test, 'fire'); | |
Test.fire(); | |
expect(Test.fire).toHaveBeenCalled(); | |
}); | |
it('triggers a click', function () { | |
$link = $('js-test-link1'); | |
spyOn($link, 'click'); | |
$link.click(); | |
expect($link.click).toHaveBeenCalled(); | |
}); | |
it('triggers a click handler', function () { | |
callback = function (foo) { } | |
spyOn(window, 'callback'); | |
$link = $('.js-test-link1'); | |
$link.click(function () { | |
callback('bar'); | |
}); | |
$link.click(); | |
expect(window.callback).toHaveBeenCalled(); | |
expect(window.callback).toHaveBeenCalledWith('bar'); | |
// expect(test).toEqual('hello'); | |
}); | |
it('triggers a TrackEvents callback', function () { | |
callback = function (message, properties) { } | |
spyOn(window, 'callback'); | |
TrackEvents.onClickEvents(function (message, properties) { | |
callback('foo', 'bar'); | |
}); | |
$link = $('[data-track-onclick-event]').first(); | |
$link.click(); | |
expect(window.callback).toHaveBeenCalled(); | |
expect(window.callback).toHaveBeenCalledWith('foo', 'bar'); | |
}); | |
it('triggers an Analytical.event when a watched link is clicked', function () { | |
Analytical = { | |
event: function () {} | |
} | |
spyOn(Analytical, 'event'); | |
TrackEvents.onClickEvents(); | |
$link = $('[data-track-onclick-event]').first(); | |
$link.click(); | |
expect(Analytical.event).toHaveBeenCalled(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment