How to test a service that extends TypeOrmCrudService.
See original GitHub issuei am trying to unit test a basic service, which just extends typeormservice but gets the error below.
The service was implemented has follows
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { TypeOrmCrudService } from '@nestjsx/crud-typeorm';
import { Authorization } from '../models/author.entity';
import { Repository } from 'typeorm';
/**
* CRUD service for Authorization model
*/
@Injectable()
export class AuthorService extends TypeOrmCrudService<Authorization> {
constructor(@InjectRepository(Authorization) public repository: Repository<Authorization>) {
super(repository);
}
}
```
Is there away to test or format, i had check through the typeormservice with little luck. thank you.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9
Top Results From Across the Web
How to create a service test with NestJS + Nest Crud?
Does anyone know what is the correct way to test a service on NestJS using the Crud library? This is my service test...
Read more >Testing Services | Nestjs-query - Blog
It is possible to test services that use TypeOrmQueryService. The process is similar to the one described for nestjs, but it has a...
Read more >Developers - Extend CrudService as mixin - - Bountysource
... for creating a new TypeOrmCrudService class extensions and if it works I would like to try to also use this pattern for...
Read more >NestJS — Fast & Simple CRUD RESTfull API - Medium
With @nestjsx/crud our service has only a few lines and it makes all ... export class UserService extends TypeOrmCrudService<UserEntity> {
Read more >NestJS and React Admin with Amazon Lambda - Endertech
Swagger, which helps us visualize and test our API: ... { super(repo); } } @Injectable() export class UserTypesService extends TypeOrmCrudService<UserType> ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I resolved this kind of error by using the mock class presented by @Darkein here: https://github.com/nestjsx/crud/issues/325#issuecomment-566666542 and adding the
metadata
property like the following:public metadata = { connection: { options: { type: null } }, columns: [], relations: [] }
So the final mock class for a repository is like below:
Not working for me:
TypeError: Cannot read property ‘options’ of undefined in constructor of service.