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.

Mocked method arguments not allowed when verifying method was called

See original GitHub issue

First of all, awesome library! Started looking at options for a new project yesterday and I’m already hooked.

I encountered one issue trying to verify that a method on a mock object has been called. I’m mocking Aurelia class from the aurelia framework. See the type definition here: https://github.com/aurelia/framework/blob/master/dist/aurelia-framework.d.ts#L35

Calling setRoot(arg) is allowed on the mock object but not when verifying that it has been called. The problem looks like this in my editor: image image

The two overloads for setRoot() visible in intellisense look like this: image image

Aurelia.setRoot(...) doesn’t really have overloads. But, the real one is not anymore available when calling setRoot() after received(): image

Do you happen to know what could cause this issue?

Luckily, there is a workaround that allows the method to be called with an argument and the test to pass:

(aurelia.received(1) as Aurelia).setRoot("gui/suite-gui");

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ffMathycommented, Mar 15, 2019

Still investigating.

0reactions
ulrichsgcommented, Jul 3, 2019

I’ve run into the same issue with the Counter.inc() method from https://www.npmjs.com/package/prom-client. In this case there are also two overloads, with one having a mandatory parameter and the other one having only optional parameters (https://github.com/siimon/prom-client/blob/master/index.d.ts#L183). The parameter I am passing is actually the mandatory one. Here’s a minimal example:

import { Substitute } from '@fluffy-spoon/substitute';
import { Counter} from 'prom-client';

describe('Potential issue with received()', () => {
  it('fails with "TS2554: Expected 0 arguments, but got 1"', () => {
    const mockedCounter = Substitute.for<Counter>();
    mockedCounter.inc({ foo: 'bar' });
    mockedCounter.received(1).inc({ foo: 'bar' });
  });
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to verify mocked method not called with any combination ...
How can I verify that a mocked method was not called at all - with any combination of parameters - using Mockito?
Read more >
Mockito - when() requires an argument which has to be 'a ...
Mockito - when() requires an argument which has to be 'a method call on a mock'
Read more >
Mockito Tutorial: An Overview of Different Types of Matchers
Argument Capture verification is typically useful where the argument used by some stubbed method is not passed directly via a method call but...
Read more >
Verify that functions were called | Mocking | MockK Guidebook
When using mocked dependencies, you usually want to test that your code calls the correct functions. In MockK, this is accomplished using the...
Read more >
Methods of Mockito - Javatpoint
Mockito contains five mock() methods with different arguments. ... The verify() method is used to check whether some specified methods are called or...
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