javascript - checking that an event fired with mocha -


how can test element fired event mocha? i've got ugly solution working, it's not readable, takes long time time out when fails, , doesn't give failure messaging.

describe('test-element', function() {   var el;    beforeeach(function() {     el = document.createelement('test-element');   });    it('fires save event', function(done) {     el.addeventlistener('save', function() {       done();     });     el.save();   }); 

in perfect world, think cooler.

  it('fires save event', function() {     el.save();     expect(el).to.have.firedevent('save');   }); }); 

am going right way? there better approach or custom matcher library should using?

how spying on fire function...?

not sure stubbing/spying library you're using lets sinon.js. like...

var spy = sinon.spy(el, 'fire'); el.save(); expect(spy.calledwith('save')).to.be.true; 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -