Error mock Apollo: «Failed to match 1 mock for this query, which had the following variables:»
Este mock:
const linksMock = {
request: {
query: STRUCTURE_STRUCTURE_LINKS_QUERY,
variables: { id: "60217" },
},
result: { data: { dataStructure: dataStructureWithLinks } },
};
provocaba este error:
yarn test StructureStructureLinks
console.log
ERROR ApolloError: No more mocked responses for the query: query DataStructureLinks($id: ID!) {
dataStructure(id: $id) {
id
dataStructureLinks {
labels {
name
}
source {
id
currentVersion {
name
pathWithIds {
data_structure_id
name
}
}
system {
id
name
}
}
target {
id
external_id
currentVersion {
name
pathWithIds {
data_structure_id
name
}
}
system {
id
name
}
}
}
currentVersion {
id
name
}
}
}
Expected variables: {"id":60217}
Failed to match 1 mock for this query, which had the following variables:
{"id":"60217"}
Si nos fijamos en las dos últimas líneas, el error es en las comillas en «60217». Al quitarlas ya funciona:
const linksMock = {
request: {
query: STRUCTURE_STRUCTURE_LINKS_QUERY,
variables: { id: 60217 },
},
result: { data: { dataStructure: dataStructureWithLinks } },
};