My function in file user-profile.component.ts:
loadImage(file) {
const myReader: FileReader = new FileReader();
myReader.onloadend = () => {
this.imageInBase64 = myReader.result;
};
myReader.readAsDataURL(file);
}
and user-profile.component.spec.ts
it('upload image success', async () => {
const file = new File([new Blob(['123'])], 'abc.png', { type: 'image/png' });
component.loadImage(file);
expect(component.imageInBase64.length).toBeGreaterThan(0);
});
I always get "Expected 0 to be greater than 0". How to write a right unit test for this case?
I tried mockFileReader from How do I write FileReader test in Jasmine? but no luck.