typescript - mocha test the promise, catch exception case -
i have test :
it('should not save user if exists', ()=>{ var user : user = {username : 'jack', name : 'lenon'}; var user1 : user = {username : 'jack', name : 'linon'}; return repository.saveuser(user) .then((user:user)=>{ return repository.saveuser(user1) }).then((user : user)=>{ expect('second ').equals(''); }) .catch((err) =>{ expect(err).equals("a user username exist in database"); }); });
the idea test repository rejecting save second user same name. works, not happy @ way force failure in "then". there better way that?
Comments
Post a Comment