I am using graphql-tools to mock for my UI (create-react-app) functional tests. I have a question around the MockList
Currently, I am mocking by type and one of the properties is an array but I still need to be able to customise the elements in the list
e.g. I have a LineItem
type which has a mock defined as
const LineItem = () =>
({
name: 'Item name'
} as LineItemType)
and the cart type has a list of LineItem
const Cart = () =>
({
id: 'cart-id',
lineItems: [...new Array(2)],
} as ActiveCartType)
Is there a way for the item name to be different for the 2 items in the cart?
I tried to map over the Array like so
const Cart = () =>
({
id: 'cart-id',
lineItems: [...new Array(2)].map(i => ({...i, id: '123', name: 'new item name'})),
} as ActiveCartType)
But the name
doesn't change in the mock result. It is still set to Item name
. Only id
changes to 123
. Am I missing something here?