Since this is one of the top results when searching for "axios mock adaptor with token in path", I'll just point out that the GitHub README for axios mock adaptor has the solution. https://github.com/ctimmerm/axios-mock-adapter

You can pass a Regex to .onGet, so for your case -

const pathRegex = new Regexp(`${apiUrl}\/invoice\/*`);
mock
    .onGet(pathRegex).reply
...etc.etc.

That should pick up your calls to /invoice/${id}

Answer from cssiamamess on Stack Overflow
🌐
GitHub
github.com › ctimmerm › axios-mock-adapter › issues › 18
How to match against get params? · Issue #18 · ctimmerm/axios-mock-adapter
August 31, 2016 - I'm making the following request: axios.get('/api', { params: { name: 'Bob' }}) ... And I'm trying to mock it like so: mock.onGet('/api', { params: { name: 'Bob&...
Author   chipit24
🌐
npm
npmjs.com › package › axios-mock-adapter
axios-mock-adapter - npm
October 9, 2024 - const axios = require("axios"); const AxiosMockAdapter = require("axios-mock-adapter"); // This sets the mock adapter on the default instance const mock = new AxiosMockAdapter(axios); // Mock GET request to /users when param `searchText` is 'John' // arguments for reply are (status, data, headers) mock.onGet("/users", { params: { searchText: "John" } }).reply(200, { users: [{ id: 1, name: "John Smith" }], }); axios .get("/users", { params: { searchText: "John" } }) .then(function (response) { console.log(response.data); });
      » npm install axios-mock-adapter
    
Published   Oct 09, 2024
Version   2.1.0
Author   Colin Timmermans
🌐
GitHub
github.com › ctimmerm › axios-mock-adapter › pull › 130
Support matching query params for `post`, `put` methods. by thk2b · Pull Request #130 · ctimmerm/axios-mock-adapter
May 30, 2019 - Currently, it is possible to expect query params for GET, or a specific body for POST, but it is impossible to expect specific query params and a specific body. To solve this, I added a fourth argument to MockAdapter.prototype[methodName] (ie. onPost, onGet), which corresponds to the expected query parameters for the request.
Author   ctimmerm
🌐
GitHub
github.com › ctimmerm › axios-mock-adapter › issues › 139
how to ignore queryString (params) when doing a mock · Issue #139 · ctimmerm/axios-mock-adapter
May 23, 2018 - tried: mock.onGet( apiPath('/Facility') ).reply(config=>{ console.log(config); return [ 200,newItem(1) ] }) mock.onGet( apiPath('/Facility'),{ params: { facilityId: /\d+/ } } ).reply(config=>{ console.log(config); return [ 200,newItem(1)...
🌐
Tabnine
tabnine.com › home page › code › javascript › axios-mock-adapter
axios-mock-adapter JavaScript and Node.js code examples | Tabnine
it('fetches a single resource with a camelCase relationship include', async () => { expect.assertions(1) const api = new Kitsu() mock.onGet('anime/1', { params: { include: 'animeStaff' } }).reply(200, getSingleWithIncludes.jsonapi) mock.onGet('*').reply(data => console.log(data)) const request = await api.get('anime/1', { params: { include: 'animeStaff' } }) expect(request).toEqual(getSingleWithIncludes.kitsu) })
🌐
UNPKG
unpkg.com › browse › axios-mock-adapter@1.18.1 › README.md
axios-mock-adapter
## Example Mocking a `GET` request ... the mock adapter on the default instance var mock = new MockAdapter(axios); // Mock any GET request to /users // arguments for reply are (status, data, headers) mock.onGet("/users").reply(200, { users: [{ id: 1, name: "John Smith" }], }); axios.get("/...
🌐
GitHub
github.com › ctimmerm › axios-mock-adapter › issues › 88
Mock a post request with data and query params · Issue #88 · ctimmerm/axios-mock-adapter
April 16, 2017 - const getReport = (userId, managerId, start, count, refresh) => { return axios.post(url(userId), { ManagerId: managerId }, { withCredentials: true, start, count, refresh }).then(extractData) } ... mock.onPost(`http://localhost:3000/example/...
Author   DarynHolmes
🌐
TechNetExperts
technetexperts.com › home › easily mock requests with axios mock adapter
How to Use Axios Mock Adapter to Test Network Requests
November 13, 2025 - Which contains, status, data, headers ... Mock Adapter support with request parameter validation as well, So mock adapter validates request parameters and if matched then it will return a response.
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › tagged › axios-mock-adapter
Recently Active 'axios-mock-adapter' Questions - Stack Overflow
I am trying to use axios-mock-adapter to mock the response I get when calling the Spotify API to request an access token. Here is the function that does just that...
🌐
CodeSandbox
codesandbox.io › s › axios-mock-dynamic-query-string-eqzc7
Axios Mock Dynamic Query String - CodeSandbox
August 31, 2020 - Axios Mock Dynamic Query String by NearHuscarl using axios, axios-mock-adapter, react, react-dom, react-scripts
Published   Aug 31, 2020
Author   NearHuscarl
🌐
GitHub
github.com › ctimmerm › axios-mock-adapter › issues › 67
Query params not handled properly · Issue #67 · ctimmerm/axios-mock-adapter
August 4, 2017 - Looks like the mock adapter is not mutating the config by changing "/path/here?param1=value" to include: ... I came up with a workaround, but it is kind of sloppy. Importing the url module and doing this on many calls: ....... mockAdapter.onGet(/\/path\/here\/?(|\?.*)).reply((config) => { const parsedUrl = url.parse(url.resolve(config.baseURL, config.url), true, true); config.params = parsedUrl.query; .......
🌐
GitHub
github.com › ctimmerm › axios-mock-adapter
GitHub - ctimmerm/axios-mock-adapter: Axios adapter that allows to easily mock requests
const axios = require("axios"); const AxiosMockAdapter = require("axios-mock-adapter"); // This sets the mock adapter on the default instance const mock = new AxiosMockAdapter(axios); // Mock GET request to /users when param `searchText` is 'John' // arguments for reply are (status, data, headers) mock.onGet("/users", { params: { searchText: "John" } }).reply(200, { users: [{ id: 1, name: "John Smith" }], }); axios .get("/users", { params: { searchText: "John" } }) .then(function (response) { console.log(response.data); });
Starred by 3.5K users
Forked by 255 users
Languages   JavaScript 96.2% | TypeScript 3.8% | JavaScript 96.2% | TypeScript 3.8%
🌐
npm
npmjs.com › package › axios-mock-adapter-path-params
axios-mock-adapter-path-params - npm
August 29, 2020 - Axios adapter that allows to easily mock requests. Latest version: 1.20.0, last published: 4 years ago. Start using axios-mock-adapter-path-params in your project by running `npm i axios-mock-adapter-path-params`. There are no other projects in the npm registry using axios-mock-adapter-path-params.
      » npm install axios-mock-adapter-path-params
    
Published   Aug 29, 2020
Version   1.20.0
Author   SNRN
🌐
Medium
simonkkaranja.medium.com › react-testing-mocking-axios-with-axios-mock-adapter-e24752a55923
React Testing: Mocking Axios with axios-mock-adapter | by Simon Karanja | Medium
December 14, 2020 - That’s how easy it is to mock axios requests with axios-mock-adapter. Of course we have only touched one HTTP verb, GET in our tests above. That’s not all the library is capable of. It has all HTTP methods covered in case your needs goes past GET or POST.
🌐
Stack Overflow
stackoverflow.com › questions › tagged › axios-mock-adapter
Highest scored 'axios-mock-adapter' questions - Stack Overflow
I am using axios mock adapter to mock the data for my react front-end. Currently I am working with param and it was working.
🌐
GitHub
github.com › ctimmerm › axios-mock-adapter › issues › 129
Match data and params in `onPut`, `onPost` · Issue #129 · ctimmerm/axios-mock-adapter
April 19, 2018 - Mocking a GET request with specific parameters mock.onGet('/users', { params: { searchText: 'John' } }).reply(200, {...}) So, it's possible to match params for get requests, and data for put and post.
Author   thk2b
🌐
Socket
socket.dev › npm › package › axios-mock-adapter
axios-mock-adapter - npm Package Security Analysis - Socket
Axios adapter that allows to easily mock requests. Version: 2.1.0 was published by marcbachmann. Start using Socket to analyze axios-mock-adapter and ...
🌐
Tabnine
tabnine.com › home page › code › javascript › mockadapter
axios-mock-adapter.MockAdapter.onGet JavaScript and Node.js code examples | Tabnine
it('sends parameters', async () => { expect.assertions(1) const api = new Kitsu() mock.onGet(`anime/${getSingleWithIncludes.jsonapi.data.id}`, { include: 'author,comments' }).reply(200, getSingleWithIncludes.jsonapi) const request = await api.request({ method: 'GET', url: 'anime/1', params: { include: 'author,comments' } }) expect(request).toEqual(getSingleWithIncludes.kitsu) })