Skip to content

Instantly share code, notes, and snippets.

@jinzhubaofu
Created December 13, 2016 08:12
Show Gist options
  • Save jinzhubaofu/7bdc6a5e020fc9e3af1d5c4229463d85 to your computer and use it in GitHub Desktop.
Save jinzhubaofu/7bdc6a5e020fc9e3af1d5c4229463d85 to your computer and use it in GitHub Desktop.
jasmine trigger event
/**
* @file test
* @author leon <ludafa@outlook.com>
*/
describe('document click event', () => {
it('should work', done => {
let spy = jasmine.createSpy();
document.addEventListener('click', spy);
let target = document.createElement('div');
document.body.appendChild(target);
let event = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
target.dispatchEvent(event);
setTimeout(() => {
expect(spy).toHaveBeenCalled();
done();
}, 100);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment