-
Notifications
You must be signed in to change notification settings - Fork 2
Added some tests with Jest #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
yujhenchen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some comments—feel free to take a look. I'll continue reviewing the other files in the coming weeks. Thanks for your contributions and patience!
| }); | ||
|
|
||
| test('should reject an email without required fields', () => { | ||
| const invalidEmail: any = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| }); | ||
|
|
||
| test('should reject an email with invalid types', () => { | ||
| const invalidEmail: any = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
| expect(res.body.data).toBe('Operation successful'); | ||
| }); | ||
|
|
||
| it('should allow APIRequest and APIResponse without generics', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain a bit more about this test case. Why it's necessary to test if APIRequest and APIResponse can be cast as non-generic?
| const OtpModel: IOtpModel = { | ||
| create: jest.fn(), | ||
| findOne: jest.fn(), | ||
| } as any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
: IOtpModel infer the type of OtpModel, not need to tell the TypeScript compiler to treat it as any type. Besides, avoid using any
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the idea of mocking and testing these two functions—it's really helpful and great!
| createdAt: new Date(), | ||
| }; | ||
|
|
||
| (OtpModel.create as jest.Mock).mockResolvedValueOnce(otpData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the function create is defined correctly at the previous declaration step, not need to convert the data type into jest.Mock again here

I added some tests with Jest to some features.