I am doing unit tests on a react app that is using relay as a graphql client when testing , i get mocked data with like this :
title: '<mock-value-for-field-"title">',
How can i define default mock data ?
To mock the specific value of a field in Relay you will want to use MockPayloadGenerator
.
Will need more code to give a complete example but essentially will need to do something similar to:
environment.mock.resolveMostRecentOperation(operation =>
MockPayloadGenerator.generate(operation, {
String(context) {
if (context.name === 'title') {
return 'value you want to be used for title field'
}
},
}),
);