私のアプリケーションコードでMySQLのINSERT結果:私はそれが言うまさにません同じクラスの_getById
メソッドを持っているテストテストへのNode.js/Sinon
create(params) {
let result = {};
try {
result = await this.db.query('/* some query */');
} catch (e) {
throw new Error('Error creating User', e);
}
return this._getById(result.insertId);
}
...
そして、 (アヴァを通じて実行されている)私の現在のテスト:
test('it should create a user', async t => {
const db = mock({
query:() => {
},
});
const userObj = {
// some params
};
const user = new Users({
db: db.object,
});
const call = {
request: userObj,
};
const result = await user.create(call);
// test?
});
私が試してみてresult
変数、すなわちのオフに基づいて何かをテストする場合。新しく作成されたユーザーは、エラー"Cannot read property 'insertId' of undefined"
が表示されます。このcreate
メソッドが新しく作成された「ユーザー」を返すかどうかテストするために、Sinonのベスト・オプションは何ですか?