私のpostgresスキーマをテストするユニットテストを書いています。私はnode-pg、mocha、sinon、およびchaiを使用しています。失敗したときにテストがdone()を呼び出さない
は、これは動作します - テストが問題なく合格:しかし
describe('When adding a user',()=> {
it('should reject since email is used somewhere else', (done)=> {
pool.query(`INSERT INTO users(email, id, token)
VALUES($1, $2, $3)`, ['[email protected]', '12346', 'fooToken'])
.then((result)=> {
console.log('nothing in here runs, you will not see this');
done()
})
.catch((result) => {
result.constraint.should.have.string('email_already_exists');
done();
})
})
});
私は偽陽性を取得しておりませんことを確認するために、私は意図的にテストを失敗させるためにresult.constraint.should.not.have.string('email_already_exists');
にアサートを変更します。
テストに失敗する代わりに、私はError: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
を取得します。
私はこれをどうしていますか?
約束ベースのコードをテストする場合は、Mochaの組み込み[約束のサポート](https://mochajs.org/#working-with-promises)の使用を検討する必要があります。このような問題を防ぐのはずっと簡単です。 – robertklep
@robertklepノードで2つのフェッチをテストする際に、この約束のサポートをどのように使用できますか? http://stackoverflow.com/questions/43690868/how-to-assert-stubbed-fetch-more-than-once/43806205#43806205 – dman
良い例:https://coderwall.com/p/axugwa/cleaning-その質問の中で、データベースの中のmocha-tests-with-pg-promise –