'coverage issue in nestjs typeorm. ManyToOne is not getting covered

I have below entity class in nest js.

@Entity({ name: 'country' })
export class Country extends BaseEntity {
    @ApiProperty()
    @Generated('rowid')
    @Column({ name: 'country_id', type: 'varchar' })
    country_id: string;

    @ApiProperty()
    @Column({ name: 'country_name', type: 'varchar', length: 100 })
    country_name: string;

    @ApiProperty()
    @ManyToOne(() => Insurance, (insurance) => insurance.insurance_id, { eager: true, })
    @Column({ type: 'varchar', nullable: true })
    @JoinColumn({ name: 'insurance_id' })
    insurance_id: Insurance[];
}

when I am running npm run jest:coverage this line which has @ManyToOne is not getting covered.

I tried to ignore it.

 @ManyToOne( /* istanbul ignore next */ () => Insurance, (insurance) => insurance.insurance_id, { eager: true, })

still its not working. I also tried below in my services test file.

beforeEach(async () => {
        const module: TestingModule = await Test.createTestingModule({
            providers: [
                CountryService,
                Country,
                {
                    provide: getRepositoryToken(Country),
                    useValue: {
                        find: jest.fn().mockReturnValue([new Country()]),
                        findOne: jest.fn().mockReturnValue(new Country()),
                        save: jest.fn().mockReturnValue(new Country()),
                        softRemove: jest.fn().mockReturnValue(new Country()),
                        ManyToOne: jest.fn(() => Insurance)
                    },
                },
            ],
        }).compile();
        service = module.get<CountryService>(CountryService);
        repository = module.get<Repository<Country>>(getRepositoryToken(Country));
        country=module.get<Country>(Country);
    });

still, this line is not getting covered. any help to sort this out? even though I wrote entity test files still its not working? is there any way I can skip ManyToOne from coverage?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source