close
The Wayback Machine - https://web.archive.org/web/20200915172823/https://github.com/visionmedia/supertest/issues/669
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency between express and supertest when using escaped parenthesis and single quotes in routes #669

Open
mrcharrington opened this issue Aug 25, 2020 · 0 comments

Comments

@mrcharrington
Copy link

@mrcharrington mrcharrington commented Aug 25, 2020

express version: 4.17.1
supertest version: 4.0.2

TLDR; There seems to be some sort of inconsistency between express and supertest when handling routes with single quotes. Or I'm missing something trivial.

I have two express routes. I'm escaping parenthesis in the routes with \\ as suggested in the docs.
app.get('/api/hello-one\\(:msg\\)', (req, res) => res.send({ num: 1, msg: req.params.msg }));
app.get('/api/hello-two\\(\':msg\'\\)', (req, res) => res.send({ num: 2, msg: req.params.msg }));

I have two supertest tests (using mocha to run them):

it('should return correct response for hello-one', (done) => {
const app = createExpressApp(null);
console.log(app._router.stack);
request(app).get(`/api/hello-one('foo')`).expect(200).expect({ num: 1, msg: `'foo'`}, done);
});

it('should return correct response for hello-two', (done) => {
const app = createExpressApp(null);
console.log(app._router.stack);
request(app).get(`/api/hello-two('foo')`).expect(200).expect({ num: 2, msg: `foo`}, done);
});

The first test passes as expected.
The second test fails unexpectedly, with an actual status of 404 instead of the expected 200.
But in the browser (using Firefox),
GET http://localhost:<port>/api/hello-one(foo) and
GET http://localhost:<port>/api/hello-two('foo')
both return the correct objects as expected.

What's going on here? Any help is appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.