Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

341
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda