Closed jasperblues closed 5 years ago
I'm not sure what you mean here. Can you elaborate - perhaps make a full reproducable example, throwing an error?
I mean when you partially mock a class, the concrete method should be able to call other methods in the mock.
this
doesn't point to the mock class. It points to the function. This can be fixed by binding the function to the mock. Expected:
Actual:
Error: Function does not have a property named methodName
Example:
class ClientDefaultImpl {
public async authorize(token: string): Promise<string> {} //THIS IS MOCKED
public async sendBuyerData(buyerId: BuyerModel.Buyer['id'], correlationId: string): Promise<void> {
logger.info(`Posting Buyer '${buyerId} to Unipay.'`);
const token = await this.authorize(correlationId); <---- This fails on a partial mock because `this` is not bound to the mock.
const unipayCustomerUrl = `${this.baseUrl}/api/customers`;
// Fetch the buyer
// etc more implementation
}
Please reopen this issue, it is an essential feature. I can send a pull request. Let me know if the example is not clear.
A PR would be absolutely fantastic.
I'm still not sure what you mean though.
Can you provide an example with a unit test that fails?
OK, let's establish the problem with an example first. Stay tuned . . (it might take a few days, under the hammer here a bit, a the moment).
Closing until I hear more. Looking forward to it <3
Steps to Repro:
*Mock the authorize method:
Test:
Expected:
This is the mock's this.
Actual:
This points to the function. A class's methods can't call other methods.