I'm really not sure how to approach testing this? (spyOn?)
function reloadPage() {
$('#logo').click(function() {
location.reload();
})
}
Any advice would be great!
I'm really not sure how to approach testing this? (spyOn?)
function reloadPage() {
$('#logo').click(function() {
location.reload();
})
}
Any advice would be great!
The reason you may be unsure about how to test this piece of code is because it's doing 2 different things and you should break it up into smaller chunks.
I see two distinct functions here:
So why not break up the logic like so?
Now you can test them separately using Spies:
There's not much need to test that the
reloadPage
handler was correctly added to the#logo
's click event because the test is simulating a.click()
and checking ifreloadPage
gets called or not.So most likely you'd only need to have the
it('will reload the page')
spec, not both.