Just getting started with Jest and have a question:
Let's say I have a function that includes a const
set to a specific type (newArtist
):
export class myTestClass {
async map(document: string) {
const artist: newArtist = document.metadata.artist;
...
}
}
And I also have:
export interface newArtist {
name: string;
title: string;
}
Now for my test, if I try something like this:
it("Sample test", async () => {
const result: any = await new myTestClass(__context()).map({
name: "An Artist"
title: null
});
...
}
The test fails because title
is set to null. I need the interface to allow null values for the test, like this:
export interface newArtist {
name: string;
title: string | null;
}
How can I achieve that? I've heard of mocking classes, but isn't that just copying and pasting the code from the map
function?
Any guidance is appreciated.
Thank you.