как мне использовать assert.reject в машинописи с обещанием в параметрах?
вот мой код:
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как обещание, но пример не очень ясен в их репозитории github.
Визит https://github.com/domenic/chai-as-promised#readme
Источник: https://www.npmjs.com/package/chai-as-promised