Skip to content
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

[HowTo] How to mock "req" - testing service method #791

Open
fider-apptimia opened this issue Jun 3, 2022 · 0 comments
Open

[HowTo] How to mock "req" - testing service method #791

fider-apptimia opened this issue Jun 3, 2022 · 0 comments

Comments

@fider-apptimia
Copy link

fider-apptimia commented Jun 3, 2022

My code and what's wrong:

beforeAll(async () => {
    module = await Test.createTestingModule({
        imports: [AppModule],
    }).compile();

    myService = module.get(MyService);
});

test(async () => {
    await myService.createOne(req, {...});
})

[..]

@Injectable()
export class MyService extends TypeOrmCrudService<MyRepo> {
  constructor(
    @InjectRepository(MyRepo)
    private myRepository: Repository<MyRepo>
  ) {
    super(myRepository);
  }
}

How can I mock req?

Error messages are like below:

Cannot read property 'routes'
// etc.

Question - How to mock req parameter to not break anything else?

Environment


Package version:
- "@nestjs/core": "^8.0.0"
- "@nestjsx/crud": "^5.0.0-alpha.3"
- "@nestjsx/crud-typeorm": "^5.0.0-alpha.3"

 
For Tooling issues:
- Node version: 14.19.3
- Platform:  Linux (ubuntu 20.04)
- Database: Postgres 14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant