最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

我是如何通过测试用例的。是不是少了什么

网站源码admin51浏览0评论

我是如何通过测试用例的。是不是少了什么

我是如何通过测试用例的。是不是少了什么

auth.service.spec.ts 这是我的测试文件。

import { auth_service } from "../../../src/backend/services/auth.service";
import { AppError } from "../../../src/utility/AppError";
const mockSignUpUser: IAuthSignupPayload = {
first_name: "Suraj",
last_name: "Chand",
username: "suraj_chand",
phone: "0000000001",
email: "[email protected]",
password: "Player@123",
confirm_password: "Player@@123",
referral_code: "",
terms_and_conditions: true,
newsletter_subscriber: false
};

describe("SignUp User service", () => {
it("should throw password and confirm password are not matched error", async () => {
const mockReq = ((mockRequest().body as any) = { body: mockSignUpUser });
const mockRes = mockResponse();
    await auth_service.signup(mockReq.body);
    expect(() => auth_service.signup(mockReq.body)).toThrow(AppError);

});
});

auth.service.ts

const signup = async (value: IAuthSignupPayload): Promise<IUserAuth> => {
if (value.password !== value.confirm_password) {
throw new AppError(`Password and Confirm Password are not matched !!`, 400);
}
}

AppError.ts

export class AppError extends Error {
statusCode: number;
success: boolean;
isOperational: boolean;

constructor(message: string, statusCode: number) {
super(message);
this.message = message;
this.statusCode = statusCode || 500;
this.success = false;
this.isOperational = true;
Error.captureStackTrace(this, this.constructor);
}
}

我尝试测试时的控制台 .

我用Jest做测试,用ts表达。 探索了很多但无法得到想要的答案。我没有使用酶,所以请回答纯用笑话编写的测试用例。

回答如下:
发布评论

评论列表(0)

  1. 暂无评论