=> {
let onboardingService: OnboardingService;
let prismaService: jest.Mocked<PrismaService>;
beforeAll(async () => {
const { unit, unitRef } = TestBed.create(OnboardingService).compile();
onboardingService = unit;
prismaService = unitRef.get(PrismaService);
});
afterEach(() => {
jest.clearAllMocks();
});
it(`should throw an error if the referral code has been used more than ${REFERRAL_LIMIT} times`, async () => {
jest
.spyOn(prismaService.referralCode, 'findUniqueOrThrow')
.mockResolvedValueOnce({
code: 'code',
usage_count: REFERRAL_LIMIT + 1,
used_code: 'code',
type: 'USER' as ReferralType,
user_id: 'user_id',
discount: new Decimal(0),
referred_by: null,
fulfilled_referrals: null,
});
const user = getRandomUser();
jest.spyOn(prismaService, '$transaction').mockResolvedValueOnce(unknown);
await expect(
onboardingService.updateUserReferrals({ code: 'code', user: user }),
).rejects.toThrow(BadRequestException);
});
});
I get the following error:
OnboardingService.updateUserReferrals › should throw an error if the referral code has been used more than 5 times
Cannot spy the findUniqueOrThrow property because it is not a function; undefined given instead
124 | it(`should throw an error if the referral code has been used more than ${REFERRAL_LIMIT} times`, async () => {
125 | jest
> 126 | .spyOn(prismaService.referralCode, 'findUniqueOrThrow')
| ^
127 | .mockResolvedValueOnce({
128 | code: 'code',
129 | usage_count: REFERRAL_LIMIT + 1,
at ModuleMocker.spyOn (node_modules/jest-mock/build/index.js:783:15)
at Object.<anonymous> (src/onboarding/onboarding.service.spec.ts:126:8)
Стикер
Обсуждают сегодня