UNPKG

graphql-validity

Version:

Make business logic validation easy on the graphql side without adding any declarations or modifications to the existing graphql schema.

17 lines (16 loc) 567 B
import * as sinon from "sinon"; export function mockModule<T extends { [K: string]: any }>( moduleToMock: T, defaultMockValuesForMock: Partial<{ [K in keyof T]: T[K] }> ) { return ( sandbox: sinon.SinonSandbox, returnOverrides?: Partial<{ [K in keyof T]: T[K] }> ): void => { const functions = Object.keys(moduleToMock); const returns = returnOverrides || {} as any; functions.forEach((f) => { sandbox.stub(moduleToMock, f).callsFake(returns[f] || defaultMockValuesForMock[f]); }); }; }