I am trying to write a unit test with Jest for a service in angular app and I have a question about how to mock a data. As part of my mock data I need to mock Array<App>
which has an interface like this
interface App {
Color: string;
Id: string;
Size: TileSize;
Text: string;
Title: string;
Url: string;
}
so I tried to mock the data like this in my test file:
const Apps: Array<App> = [
{
'Id': 'Chat',
'Text': 'Chat',
'Title': 'Go to your chat',
'Url': 'https://chat.com'
},
{
'Id': 'Mail',
'Text': 'Mail',
'Title': 'Go to your Mail',
'Url': 'https://mail.com'
}
];
MockConfigParserService.mockImplementation(() => {
return {
parse: () => {
return {
workloads
};
}
};
});
My test fails running the service that I am testing by throwing this error
Unhandled Promise rejection: workloads.slice is not a function ; Zone: ProxyZone ; Task: Promise.then ; Value: TypeError: workloads.slice is not a function
at this line of code in service code (the service works fine outside of test): return this.appsPromise.then(apps => [...apps]);
how should I change mock data for array of apps so it doesn't throw this error? Thanks a lot in davance