Я пытаюсь протестировать код tryCatch с шуткой, но продолжаю получать сообщение об ошибке, в настоящее время я попробовал
student. js
async checkStudentExist(studentName) {
try {
const studentExist = await this.StudentRepository.getOne({name: studentName})
if (studentExist) {
throw new Error(`Student already exist with the name: ${studentName}`)
}
return studentExist
} catch (error) {
throw error
}
}
student.test . js
it('should throw an error if the input name already exist in database', async () => {
mockGetOne.mockReturnValue(Promise.resolve(expectedOrganization))
await studentService.checkStudentExist('john doe')
expect(mockGetOne).toHaveBeenCalledWith({name: 'sample org'})
expect(studentService.checkStudentExist('john doe')).resolves.toThrowError(new Error(`Organization already exist with the name: john doe`))
})
и это ошибка, которую я получаю
FAIL test/specs/services/student_service.test.js
● Console
console.log src/services/student_service.js:53
111
console.log src/services/student_service.js:53
111
● Check if Student exist › should throw an error if the input name already exist in database
Student already exist with the name: john doe
55 | const studentExist = await this.StudentRepository.getOne({name: studentName})
56 | if (studentExist) {
> 57 | throw new Error(`Student already exist with the name: ${studentName}`)
| ^
58 | }
59 | return studentExist
60 | } catch (error) {
at StudentService.checkStudentExist (src/services/student_service.js:57:23)