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

144
Views
Prueba de mutación fallando con executeOperation (Apollo Graphql)

Quiero probar mis consultas y mutaciones de graphql usando Jest. Estoy escribiendo mis pruebas unitarias como se indica en los documentos de Apollo :

 describe('Tests', () => {
 let testServer;

 beforeAll(() => {
 testServer = new ApolloServer({ typeDefs, resolvers });
 });

 // Below test passes 
 it('should return matching result for the movies query', async () => {
 const limit = 3;
 const query = `
 query {
 movies(limit: ${limit}) {
 id
 name
 }
 }
 `;

 const result = await testServer.executeOperation({ query });
 expect(result.data.movies.length).toBe(limit);
 });

 // Below test fails.
 it('should mark movie as watched using the markWatched mutation', async () => {
 const movieIds = [9873, 8754];
 const mutation = `
 mutation {
 markWatched(movieIds: ${movieIds}) {
 id,
 watched
 }
 }
 `;

 const result = await testServer.executeOperation({ query: mutation });
 expect(result.data.markWatched).toBe([
 {
 id: 9873,
 watched: true
 },
 {
 id: 8754,
 watched: true
 }
 ]);
 });
});

// Mutation
 type Mutation {
 markWatched(ids: [ID]!): [Movies]!
 }

// Resolver
Mutation: 
{
 markWatched: (_, { ids }) => 
 markMoviesAsWatched(ids)
}

// Data model (which is simply a local file exporting an array - moviesData in below code)
const markMoviesAsWatched = ids => {
 const response = [];
 moviesData.forEach(movie => {
 if (ids.includes(movie.id)) {
 movie.watched = true;
 response.push(movie);
 }
 });
 return response;
};

La primera prueba con respecto a la consulta está pasando, mientras que la segunda prueba con respecto a la mutación falla con el error: TypeError: Cannot read properties of undefined (reading 'markWatched') . La mutación exacta funciona bien en el patio de recreo de Apolo. ¿No está seguro de lo que está mal con mi prueba de mutación?

almost 4 years ago · Santiago Trujillo
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!