javascript - Location reload in Jasmine -
I'm not really sure how to test it? (SpyOn?)
function Reload page () {$ ('# Logo'). Click (function () {location.reload ();})}
Any advice will be great!
The reason for this is how you test this piece of code because it is 2 different
- Click on event handling
- Reload page
So why not break the logic?
Function Reload Page () {location.reload (); } Function Bind Aventus () {$ ('# Logo'). Click (reload page); }
Now you can test them separately by using spies:
Description ('When the logo is clicked', the function () {Var logo; var handlers; first (each handle (handle) {handlers = {locationReload: location.reload, // handles for location. Reload () reload page: reload page / handle for your reload page ()}; Logo = $ ('# Logo'). ReloadPage); // Attach the detective to the reloaded page and call the function via spyOn (handler, 'reload Page '). And attach the spy on location.reload (); spy on (handler,' space reload ');}); (' will load the page function execution ', function () {logo Hopefully ('click'); hopefully (handlers. Reloaded page) .Hobbine collade ();}); ('Page will be reloaded', function () (Logo.trigger ('click'); Hopefully ( Handlers. Location Transfer) .toHaveBeenCalled ();}); After each (function () {// clear the event binding after each tTT logo.off (' It is not necessary to test that the reloadpage
handler is correctly configured by #logo
has been added to the event because the test is simulating a .click ()
and checks that the reload page is called
or not. So it is most likely that you will only need ('will reload the page')
not both, the spec.
Comments
Post a Comment