0

我正在尝试检查拒绝承诺的错误消息,如果我在测试中使消息字符串错误,它仍然通过。

MyService.doSomething({ id: 12345 }).should.eventually.be.rejectedWith(TypeError, 'no attr foo defined2');



  svc.doSomething = function(thing){
    var def = $q.defer();

    if ( !thing.foo ) {
        def.reject(new Error('no attr foo defined'));
    } else {
        def.resolve(thing);
    }

    return def.promise;
  };

更新,看来我的测试无法正常工作。当我返回它时:

  it.only('should error', function(){
    // todo this should fail but it just times out
    return MyService.doSomething({ id: 12345 }).should.eventually.be.rejectedWith(TypeError, 'no attr foo defined2');
  });







  svc.doSomething = function(thing){
    var def = $q.defer();

    if ( !thing.foo ) {
        def.reject(new Error('no attr foo defined'));
    } else {
        def.resolve(thing);
    }

    return def.promise;
  };

这是错误:

Error: timeout of 4000ms exceeded. Ensure the done() callback is being called in this test.
4

1 回答 1

0

您忘记了调用之前的最终和返回。!

return MyService.doSomething({ id: 12345 }).should.eventually.be.rejectedWith...
于 2016-04-15T20:23:33.670 回答