My coverage gives only 75%, I would like to get 100% of coverage.
Here is my TS file:
export default class MyClass {
constructor(){
this.render();
}
render() {
const el:HTMLInputElement = document.createElement('input') as HTMLInputElement;
const link:HTMLAnchorElement = document.createElement('a') as HTMLAnchorElement;
const container:HTMLBodyElement = document.querySelector('body') as HTMLBodyElement;
link.innerHTML = "Click Me!";
link.setAttribute('href', '#');
link.setAttribute('target', '_blank');
el.setAttribute('type', 'file');
container.appendChild(el);
container.appendChild(link);
el.addEventListener('change', (event) => {
if('files' in el) {
const availFile = el.files[0];
const blob = new Blob([availFile], { type: availFile.type});
const objectURL = window.URL.createObjectURL(blob);
link.setAttribute('href', objectURL);
}
})
}
}
new MyClass();
Here is my spec file:
import MyClass from "./index";
jest.mock('./index');
describe("testing as first", () => {
it("we can test the constructor", () => {
const myClass = new MyClass();
expect(MyClass).toHaveBeenCalledTimes(1);
});
it('will render element', () => {
const myClass = new MyClass();
myClass.render();
expect(document.querySelector('input')).toBeTruthy();
expect(document.querySelector('a')).toBeTruthy();
})
});
I don't have any idea to reach 100%.
Aucun commentaire:
Enregistrer un commentaire