Stopping event's propagation does not work in angular 2+ unit tests -


i trying write unit test angular 4 uses event propagation stopping.

here simple scenario - register 3 listeners , call event.stopimmediatepropagation() in first listener. fire event , expect 2 last listeners not called. called.

describe('events testing demo', () => {   let count = 0;    it('should test listeners', () => {     document.body.addeventlistener('click', (event: mouseevent) => {       event.stopimmediatepropagation();       console.log('listener 1 running');       count++;       event.stopimmediatepropagation();     });      document.body.addeventlistener('click', (event: mouseevent) => {       console.log('listener 2 running');       count++;     });      document.body.addeventlistener('click', (event: mouseevent) => {       console.log('listener 3 running');       count++;     });      document.body.dispatchevent(new event('click'));      expect(count).toequal(1); // because of event.stopimmediatepropagation() in 1st listener   }); }); 

this describe block can added "hello world" app generated angular cli, see in action.

but works fine in jasmine standalone test (directly in browser, without angular), seem angular-specific issue.

or maybe not correct way test dom events in angular?


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -