typescript で assert.reject を使用し、params で promise を使用するにはどうすればよいですか?
ここに私のコードがあります:
import { assert } from "chai";
import { suite, test, timeout, slow } from "mocha-typescript";
import "mocha";
import { car } from "./Car"; // module that run your function
let carVIN: string = "1234567890"; // this car has four wheel;
@suit
export class CarTest() {
@test
public async oneWheelsCar() {
const wheels = await car.findWheelsByCarId(carVIN);
assert.isRejected(wheels, "Expected to have four wheels");
}
}
私の質問は、carId エラーが戻る前に assert.isRejected が早期に実行されるため、carId 関数を約束のように実行するにはどうすればよいかということです。
私はこれを以下で試しました:
assert.throws(carId, Error, "Expected to be error ");
また、try-catch を使用して関数をラップしようとしています。
import { assert } from "chai";
import { suite, test, timeout, slow } from "mocha-typescript";
import "mocha";
import { car } from "./Car"; // module that run your function
let carVIN: string = "1234567890"; // this car has four wheel;
@suit
export class CarTest() {
@test
public async oneWheelsCar() {
try {
const wheels = await car.findWheelsByCarId(carVIN);
assert.isNotString(wheels, "Expected to be error but return four wheels");
} catch (error) {
assert.throws(error, Error, "Expected to be error ");
}
}
}
私は chai-as-promise を使用しようとしましたが、その例は彼らの github リポジトリでは明確ではありません。
https://github.com/domenic/chai-as-promised#readmeにアクセスしてください