You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/docs/developer-resources/testing.md
+58Lines changed: 58 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -59,6 +59,64 @@ The `tests/server.ts` file exports the Talawa API server instance that can be im
59
59
60
60
There aren't any other strict structure requirements for the this directory.
61
61
62
+
# Mock GraphQL Context Factory Function
63
+
In Directory `test/MockContext/*`
64
+
65
+
## **Purpose**
66
+
The `createMockGraphQLContext` function provides a **fully mocked GraphQL context** for unit and integration testing of GraphQL resolvers. It ensures that resolvers can be tested **without needing a real database, MinIO storage, or authentication service** and works as centralised mocking mechanism.
const result =awaituserResolver({}, {}, mockContext);
112
+
expect(result.id).toBe("user123");
113
+
});
114
+
```
115
+
116
+
## **Key Benefits**
117
+
**Isolated Testing** – No need for a real database or external services.
118
+
**Scalable** – Any future changes in `GraphQLContext` can be updated in one place, ensuring a single source of truth.
119
+
62
120
### Future Considerations
63
121
64
122
In the future there might be a requirement to run some tests sequentially. When that moment arrives separating sequential and parallel tests into separate directories and using separate vitest configuration for them would be the best idea.
0 commit comments