Partial mock `this` in a mimick function is not the mock's `this`
See original GitHub issueSteps to Repro:
- Create an interface:*
export interface Client {
authorize(correlationId: string): Promise<string>;
sendBuyerData(buyerId:string, correlationId: string): Promise<void>;
}
*Mock the authorize method:
const partialClient = Substitute.for<Client>();
partialClient.sendBuyerData(Arg.all()).mimicks(client.sendBuyerData);
partialClient.authorize(Arg.any()).returns(Promise.resolve(uuid()));
Test:
public async sendBuyerData(buyerId: string, correlationId: string): Promise<void> {
const token = await this.authorize(correlationId);
//etc
Expected:
This is the mock’s this.
Actual:
This points to the function. A class’s methods can’t call other methods.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Partial module mock function created using Jest is not called ...
So all Jest is doing is mocking strawberry for any other modules that import it later on, e.g. your test suite.
Read more >Creating Partial Mocks - Mockery Docs
A proxied partial mock is a partial of last resort. We may encounter a class which is simply not capable of being mocked...
Read more >Java – Partial Mock Private Method with PowerMock-Mockito
I am considering using the private partial mocking feature from PowerMock, I tried to mimic the example from the link, but it failed....
Read more >Mimic - A mocking library for Elixir - GitHub
copy(MyModule) , calls to functions belonging to this module will first go through an ETS table to check which pid sees what (stubs,...
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 FreeTop 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
Top GitHub Comments
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 ❤️