Skip to content

Cannot mock callable interface #178

Description

@vincentvanderweele

Describe the bug
Some third-party libraries (typically js-native with ts types added later) provide callable interfaces. It seems that methods on those callable interfaces cannot be mocked with this library (or I haven't figured out how).

To Reproduce

interface Library {
  subSection: Subsection;
  coreMethod: () => string;
}

interface Subsection {
  (): string;
  subMethod: () => string;
}

const lib: SubstituteOf<Library> = Substitute.for<Library>();

// I can mock coreMethod()
lib.coreMethod().returns('hello');

// I can mock subSection()
lib.subSection().returns('hello');

// I can't mock subSection:

// Property 'returns' does not exist on type 'NoArgumentFunctionSubstitute<string> & Subsection'.
lib.subSection.returns({ subMethod: () => 'hello' });

// Property 'returns' does not exist on type 'string'.
lib.subSection.subMethod().returns('hello');

Expected behavior
I would like to be able subMethod in some way. I'm okay with a workaround but not sure what that should be.

Environment

  • Typescript version: 4.1.2
  • substitute.js version: 1.179.0
  • Node version: v14.12.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions