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

Indentation issue with graphQL mock #5495

Closed
6 tasks done
sbrauch opened this issue Apr 5, 2024 · 1 comment
Closed
6 tasks done

Indentation issue with graphQL mock #5495

sbrauch opened this issue Apr 5, 2024 · 1 comment

Comments

@sbrauch
Copy link

sbrauch commented Apr 5, 2024

Describe the bug

When I try to declare a graphQL expect clock with toHaveBeenCalledWith I get this error
image

When I change to the (wrong) indentation, the test passes
image

Reproduction

Create a graphQL query and try to mock it with an expect "toHaveBeenCalledWith" block.

Entire test:

`describe("getUserPreferences", () => {
it("fetches user preferences when preferences available", async () => {
(axios.post as any).mockResolvedValue({
data: {
findPreferences: [
{
ldap: "testLdap",
buCode: "testBuCode",
preferenceKey: "testPreferenceKey",
preferenceValue: "testPreferenceValue",
},
],
},
});

const ldap = "testLdap";
const buCode = "testBuCode";

const result = await getUserPreferences(ldap, buCode);

expect(result).toEqual({
  data: {
    findPreferences: [
      {
        ldap: "testLdap",
        buCode: "testBuCode",
        preferenceKey: "testPreferenceKey",
        preferenceValue: "testPreferenceValue",
      },
    ],
  },
});

// PAY ATTENTION TO SPECIAL INDENTATION OF "QUERY" HERE TO MAKE THE TEST PASS
expect(axios.post).toHaveBeenCalledWith("/users/graphql", {
  query: `query findPreferences($ldap: String!, $buCode: String!) {
  findPreferences(ldap: $ldap, buCode: $buCode) {
    ldap
    buCode
    preferenceKey
    preferenceValue
  }
}`,
  variables: { buCode: "testBuCode", ldap: "testLdap" },
});

});`

System Info

Mac OS, vue3 3.4.21, vitest 1.3.1, vite 5.1.5

Used Package Manager

npm

Validations

Copy link

github-actions bot commented Apr 5, 2024

Hello @sbrauch. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 9, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Apr 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants