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.

Missleading regex example

See original GitHub issue

When using a regex expression, requests don’t get caught by the adapter in some cases

This works :

const axios = axios.create({
  baseURL: 'https://apiurl.com'
})
axios.get('/foo/123').then(function (data) {
  console.log(data)
})

mock.onGet(/\/foo\/\d+/).reply(function(config) {
  return [200, {}];
})

This doesn’t :

const axios = axios.create({
  baseURL: 'https://apiurl.com/'
})
axios.get('/foo/123').then(function (data) {
  console.log(data)
})

mock.onGet(/\/foo\/\d+/).reply(function(config) {
  return [200, {}];
})

It is due to the trailing slash in the baseURL.

Is there a way to fix that (in handleRequest function for example) or at least change the documentation ?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
zzx18023commented, Aug 17, 2020

2020-08-17 The problem remains unsolved

2reactions
wateryomacommented, Jul 21, 2017

sure, here is mock regexp mock not working, but with “fix” i wrote above it’s working

i use webpack-everything as a starter in this project, just clone repo, install dependencies and run

yarn && yarn dev

open localhost:3000 and navigate to localhost:3000/test then watch console i doubt that this is issue with axios-mock-adapter, but it’s definitely a strange one

Read more comments on GitHub >

github_iconTop Results From Across the Web

Examples of regular expressions - Google Workspace Admin ...
Examples of regular expressions · baloney · darn · drat · fooey · gosh darnit · heck.
Read more >
regex - Is it possible to create wrong Regular expression in ...
I've tried so many weird regexpes in Flex and Flex never complained! How do I know If my regexp valid? regex · apache-flex...
Read more >
CWE-185: Incorrect Regular Expression (4.9) - MITRE
Demonstrative Examples. Example 1. The following code takes phone numbers as input, and uses a regular expression to reject invalid phone numbers.
Read more >
A look at using Regular Expressions (RegEx) - YouTube
In this video I wanted to explore RegEx as it's so powerful and can ... 59:05 - Example RegEx I use to scrap...
Read more >
Regular Expressions :: Eloquent JavaScript
A regular expression is a type of object. It can be either constructed with the RegExp constructor or written as a literal value...
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