-1
I have a Code Jest who should test a business rule that says:
No client must have an invalid CPF
it(" should not be able to create a new user whith a wrong CPF",async()=>{
const repositoryFake = new FakeUserRepository();
const createUserService = new CreateUserService(repositoryFake);
expect(await createUserService.execute({
name:"Joao Geraldo da Cruz",
password:"321",
cpf:"50989120003",
})).rejects.toBeInstanceOf(Error)
})
However, when calling the service, it breaks the code:
public async execute({name, password, cpf}:IUserInterface):Promise<User> {
if (cpf) {
if (!DocumentValidation.cpf(cpf)) {
//ele cai nessa validação aqui
throw new Error("CPF not is valid");
}
}
const user = await this.repository.create({
name, password, cpf
});
return user;
}
The system was actually expected to break down, but Jest should understand this as "normal" and give sucess.
resolved here Thanks!!!
– Matheus