Skip to content

Setting a duplicate search parameter using Interceptor.query should throw an error #1623

@mastermatt

Description

@mastermatt

Context
#1614 (comment)

In order to gain full code coverage, a test was added to show current expected behavior around what happens if a search param is set twice.

nock('http://example.test')
    .get('/')
    .query({ foo: 'bar' })
    .query({ foo: 'baz' })
    .reply()

Current behavior prefers the first value and silently ignores any subsequent values. This example will match http://example.test?foo=bar.

This is confusing and probably hides unintended bugs by users.

Alternatives

Interceptor.query should throw an error if a duplicate key is provided with a clear error message.
The "key" being checked should be the value returned by formatQueryValue instead of the input key.

The new test from #1614 should be updated test the new expected behavior.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions