This test fails with a 404 error, can someone help me figure out what is wrong because I really don’t see the issue, I need a second pair of eyes I think. I am trying to mock a Microsoft Graph API request to remove someone from an Entra group. It works fine the actual code but I am trying to write an integration tests with a mock backend as you can see.
import axios from "axios";
import express from "express";
import { Server } from "http";
describe.only("fourohfour", () => {
const app = express();
app.use(express.json());
// Entra remove member
app.delete("graph/groups/:group/members/:userId/$ref", (req, res) => {
console.log(`ENDPOINT remove ${req.params.group} ${req.params.userId}`);
res.sendStatus(200);
});
let server: Server;
beforeAll(done => {
server = app.listen(3001, done);
});
afterAll(async () => {
server.close();
});
it("should not four oh four", async () => {
const res = await axios.delete(
"http://localhost:3001/graph/groups/123/members/456/$ref",
);
expect(res.status).toBe(200);
});
});
2
Answers
I found the reason, the
$
character in the express router needs to be escaped like\$
, therefore the solution:As the express documentation states:
So in your case changing the route schema to:
should do the trick.