如何在Jest中测试以下功能?
export async function getPdfFile() {
try {
const res = await fetch(SOME_URL_TO_PDF);
const blob = await res.blob();
return blob;
} catch ( error ) {
throw new Error( 'ERROR' );
}
}
到目前为止,我已经设法编写了以下测试,但是由于响应无法匹配,因此无法正常工作:
import {getPdfFile} from "../../services/PdfService";
const response = {Blob: 'test.pdf'};
describe('Testing the download service', () => {
it( 'Function returns a correct result', async () => {
fetchMock.mock( `${SOME_URL_TO_PDF}`, response );
expect( await getPdfFile() ).toEqual( 'test.pdf' );
});
});