question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Partial mock `this` in a mimick function is not the mock's `this`

See original GitHub issue

Steps 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:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jasperbluescommented, Feb 14, 2019

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).

0reactions
ffMathycommented, Feb 24, 2019

Closing until I hear more. Looking forward to it ❤️

Read more comments on GitHub >

github_iconTop 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 >
Mocking | Guide - Vitest
A blazing fast unit test framework powered by Vite.
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found