2017-09-19 14 views
0

私は拒否テストする必要があります方法:チャイ約束した試験拒否タイムアウトなど

私のテストで
return new Promise(function(resolve, reject){ 
      models.users.find({ 
       where: { 
        email: email 
       } 
      }).then(function(result){ 
       if(!result) 
        throw 'Invalid password' 
      }).catch(function(err){ 
       reject(err); 
      }); 
     }); 

it('should be rejected', function(){ 
      let data= { req: { 
       email: '[email protected]', 
      }}; 

      return User.authUser(data).should.be.rejected; 
     }); 

それは聖霊降臨祭エラー「無効なパスワード」を拒否しなければならないが、私はエラーを取得:

Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure 
it resolves. 
+1

return models.users.find({ where: { email: email } }).then(function(result){ if(!result) throw new Error('Invalid password'); }); 

とあなたのテストで:例外は約束を拒否し、あなたは別の約束でそれをラップするべきではありませんので、 あなたは約束を拒否する必要はありません。 find() 'がすでに約束を返しているので、' new Promise'を使ってそれをラップするべきではありません。 FWIW、あなたのコードは 'resolve()'を呼び出すことはありません... – robertklep

答えて

1

エラーメッセージが表示され、エラーメッセージが表示される可能性があります。 `models.users場合

return User.authUser(data).should.be.rejectedWith(Error).and.eventually.have.property("message").equal('Invalid password'); 
関連する問題