This is my controller class(usercontoller.ts) i am trying to write junit test cases for this class
import { UpsertUserDto } from '../shared/interfaces/dto/upsert-user.dto';
import { UserDto } from '../shared/interfaces/dto/user.dto';
import { UserService } from './user.service';
async updateUser(@BodyToClass() user: UpsertUserDto): Promise<UpsertUserDto> {
try {
if (!user.id) {
throw new BadRequestException('User Id is Required');
}
return await this.userService.updateUser(user);
} catch (e) {
throw e;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 TestClass(UserContollerspec.ts) 在运行我的测试类时出现错误“无法监视 updateUser 属性,因为它不是函数;而是给定了未定义。出现错误。但是,当我使用间谍On方法时,我不断收到 TypeError: Cannot读取未定义的属性“updateuser”:
*似乎 jest.spyOn() 在我犯错误的地方无法正常工作。有人可以帮助我吗?我正在传递的论点?
jest.mock('./user.service');
describe('User Controller', () => {
let …Run Code Online (Sandbox Code Playgroud)