Skip to content

Invalid typings of request matchers #1702

@merlinnot

Description

@merlinnot

What is the expected behavior?

I'd expect to be able to provide objects with any JSON-parseable value as request matcher, like so:

nock('https://example.com')
  .post('/path', { number: 1 })
  .reply(200);

What is the actual behavior?

Type definitions allow only strings to be passed as values.

Possible solution

Extend type definitions to include all supported types.

How to reproduce the issue

See the example code above. It will result in the TypeScript compiler error: Argument of type '{ number: number; }' is not assignable to parameter of type 'string | RegExp | Buffer | DataMatcher | ((body: any) => boolean) | undefined'.

Does the bug have a test case?

I guess it's not currently in the codebase.

Versions

Software Version(s)
Nock v11.3.2
Node v10.16.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions