javascript - mocha wait before testing a setTimeout function -


i have function calls after slight delay:

const messageboxes = {         fade: target => {         target.classlist.add('fade');         window.settimeout(messageboxes.hide, 350, target);     },     hide: el => {         el.classlist.add('displaynone');         el.parentnode.removechild(el);     } }; 

this correctly adds fade class after 350ms adds 'displaynone' class , deletes element. in mocha can simulate clicking element jsdom , check 'fade' class, want wait 350ms check 'dislpaynone' class.

all examples can find relate promises of http requests, want pause - there solution here?

you have signal end of execution mocha:

describe('settimeout test', function(){   it('use `done` callback', function(done){    window.settimeout(function(){      // assert here.      done();    }, 350);  });   it('return promise', function(){    return new promise((resolve, reject) => window.settimeout(function(){      // assert here.      resolve();    }, 350));  });  }); 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -