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

编程入门 行业动态 更新时间:2024-10-07 00:13:44

<a href=https://www.elefans.com/category/jswz/34/1767596.html style=我是如何通过测试用例的。是不是少了什么"/>

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

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表达。 探索了很多但无法得到想要的答案。我没有使用酶,所以请回答纯用笑话编写的测试用例。

回答如下:

更多推荐

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

本文发布于:2024-05-30 12:17:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770488.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我是   少了   测试

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!