Skip to content

Commit

Permalink
fix: CHECKOUT-2645 Fix callback getting called prematurely
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchin committed Nov 18, 2017
1 parent 4e1108f commit 9a2a7ec
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/form-poster.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export default class FormPoster {
postForm(url, data, callback = () => {}) {
const form = this._formBuilder.build(url, data);

window.addEventListener('beforeunload', function handleBeforeUnload() {
window.removeEventListener('beforeunload', handleBeforeUnload);
window.addEventListener('unload', function handleUnload() {
window.removeEventListener('unload', handleUnload);
callback();
});

Expand Down
2 changes: 1 addition & 1 deletion test/form-poster.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('FormPoster', () => {

const event = document.createEvent('Event');

event.initEvent('beforeunload', true, false);
event.initEvent('unload', true, false);
document.body.dispatchEvent(event);

expect(callback).toHaveBeenCalled();
Expand Down

0 comments on commit 9a2a7ec

Please sign in to comment.