Closed xenoterracide closed 3 years ago
another case/problem
I have this on my class, it uses typeorm
@OneToOne(() => StripeCustomerEntity, ({ account }) => account, { lazy: true })
readonly stripeCustomer!: Promise<Optional<StripeCustomerEntity>>;
const mockAccount = mock<AccountEntity>();
mockAccount.stripeCustomer; // this returns a promise and does not contain the methods for mocking its return
this compiles but the promise doesn't work
const mockAccount = mock<AccountEntity>({
stripeCustomer: Promise.resolve(customer0),
});
const customer1 = requireNonNullish(await repo.save(mockAccount));
TypeError: Method Promise.prototype.then called on incompatible receiver [object Object]
at Proxy.then (<anonymous>)
Have you tried
const mockAccount = mock<AccountEntity>();
mockAccount.stripeCustomer.mockResolvedValue(value)
I found that abit after updating this, which worked. but mocking the property that is a promise doesn't.
should work since we now ignore then
, Reopen if this is still an issue.
so I was going to use a deep mock for this, but didn't find a way to do it, is there a better way? if not could there be a better way?