javascript - How to mock download attribute of a link? -


i working on updating app angular 1.2 angular 1.4 , in course, broke of karma tests. easy fixes, there few can't working. tests rely on checking if download attribute defined determine how download required file. before upgrade, tests set elem.download. after upgrade, can't seem set download.

here how i'm setting element tests:

var link = document.createelement('a'); link.download = undefined; 

and in code itself, simple

if(link.download !== undefined) {     //do stuff (this test works) } else {     //do other stuff (this test doesn't work) } 

when try set link.download undefined, still going first branch. if try pass empty object in, errors because various properties undefined, though code doesn't seem looking @ properties.

i have tried setting link.download = null , changing if statement use typeof

tl;dr how set download attribute undefined?

here simple plunker issue.

the value set download converted string value, undefined getting converted "undefined" why passes !== comparison.

edit

by comments want feature detection of download. use

`download` in createelement('a') //or htmlanchorelement.prototype.hasownproperty('download') 

then if want force not exist test can delete download prototype

delete htmlanchorelement.prototype.download; 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -