Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript - "not assignable to type never" error on Entity in Jest's mockResolvedValueOnce method

I've seen this error being solved in primitive types but I am not sure how I would solve it in this example

const newUser: UserEntity = {
      user_id: 'f3bea6de-fb24-4441-b75b-d7642ca573d7',
      name: 'Test User',
    };

jest.spyOn(repo, 'create').mockResolvedValueOnce([newUser]); // error here on [newUser] - 'UserEntity' is not assignable to type 'never'

user.entity.ts

@Entity('users')
export class UserEntity {
  @PrimaryGeneratedColumn('uuid') user_id: string;
  @Column('text') name: string;
}
like image 825
asus Avatar asked Dec 02 '25 09:12

asus


1 Answers

repo.create is a synchronous function, but mockResolvedValue is for asynchronous functions that return promises. Instead, use mockReturnValueOnce and you'll have no problems.

like image 192
Jay McDoniel Avatar answered Dec 05 '25 00:12

Jay McDoniel