Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

338
Views
Pact verification failed! with console error Missing requests: GET /users/login

am very new to Pact-js and contract testing I'll try my best to explain my issue. for now, I am only trying to generate the consumer contract

here is my pact provider:

export const provider = new Pact({
    consumer: 'Users',
    provider: 'UsersService',
    port: 1234,
    log: path.resolve(process.cwd(), 'logs', 'pact.log'),
    pactfileWriteMode: 'overwrite',
    logLevel: "DEBUG",
    dir: path.resolve(process.cwd(), 'pacts'),
});

and here is my test:

jest.mock("axios");
const EXPECTED_BODY = {...}

describe("Pact tests axios", () => {
    describe("/GET login", () => {
        beforeAll(() => provider.setup());
        afterEach(()=> provider.verify())
        afterAll(() => provider.finalize());
        it("should login user and response with user object", async () => {
            await provider.addInteraction({
                state: 'user logged', uponReceiving: 'request logged user', withRequest: {
                    method: 'GET',
                    path: '/users/login',
                    body: {username: "test", password: "11223344"},
                }, willRespondWith: {
                    status: 200, headers: {
                        'Content-Type': 'application/json',
                    }, body: eachLike(EXPECTED_BODY),
                },
            });
            axios.get.mockResolvedValueOnce(EXPECTED_BODY);
            const loggedUser = await loginUser("test", "11223344")
            expect(axios.get).toHaveBeenCalledTimes(1)
            expect(axios.get).toHaveBeenLastCalledWith("http://localhost:8080/users/login", {"headers": {"Content-Type": "application/json"}, "params": {"password": "11223344", "username": "test"}})
            expect(loggedUser).toEqual(EXPECTED_BODY)
        })
    });
})

I should say that my original request takes two parameters username and password and returns an object containing all that user's information of course the user exists if not it returns null

here is the API call function if needed:

export default async function loginUser(username, password) {
    try{
        return await axios.get(("http://localhost:8080/users/login"), {
            headers: {
                "Content-Type": "application/json"
            },
            params: {
                username: username,
                password: password
            }
        })
    }catch (e){
        return null
    }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Pact expects you to actually make the call to the endpoint you're mocking in Pact.

Missing requests: GET /users/login

This error says "you said you'd make a GET call to /users/login but I didn't receive it".

jest.mock("axios");

This looks like you're mocking the HTTP client Axios. Now you have a mock for the thing that needs to send requests to the Pact Mock.

In a Pact test, think of it as a unit tests for your API client code. The actual request needs to be sent to the Pact Mock and Pact will check the correct request was made, and return back the mocked response.

So the solution is simple:

  1. Remove all of the axios mocking
  2. Provide a way to modify the API target for loginUser
  3. Configure your API client to send the request to localhost:1234 instead of the real thing before running the tests

(NOTE: you can have pact find a free port dynamically by not setting the port option, and take the host from the response from the setup() call)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!