-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Juicy/Starcounter/starcounter-include/issu…
…es/93-dispatch-load-event-for-FOUC-prevention Forward `onload` and `error` events on itself,
- Loading branch information
Showing
6 changed files
with
111 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<!doctype html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> | ||
|
||
<script src="../../webcomponentsjs/webcomponents-lite.js"></script> | ||
<script src="../../web-component-tester/browser.js"></script> | ||
|
||
<link rel="import" href="../enlighted-link.html"> | ||
</head> | ||
|
||
<body> | ||
</body> | ||
<script> | ||
let shadowHost, enlightedLink; | ||
describe('enlighted-link should dispatch', function() { | ||
let loadSpy, errorSpy; | ||
beforeEach(function() { | ||
loadSpy = sinon.spy(); | ||
errorSpy = sinon.spy(); | ||
shadowHost = document.createElement('div'); | ||
shadowHost.attachShadow({mode:'open'}); | ||
enlightedLink = document.createElement('enlighted-link'); | ||
enlightedLink.setAttribute('rel', 'import'); | ||
shadowHost.shadowRoot.appendChild(enlightedLink); | ||
}); | ||
afterEach(function() { | ||
shadowHost.parentNode && shadowHost.parentNode.removeChild(shadowHost); | ||
enlightedLink.removeEventListener('load', loadSpy); | ||
enlightedLink.removeEventListener('error', errorSpy); | ||
}); | ||
it('`load` event when link is loaded', function(done) { | ||
enlightedLink.addEventListener('load', loadSpy); | ||
enlightedLink.setAttribute('href', 'assets/doc-with-js.html'); | ||
|
||
setTimeout(()=>{ | ||
expect(loadSpy).to.be.calledOnce; | ||
expect(loadSpy.args[0][0].type).to.equal('load'); | ||
done(); | ||
}, 200); | ||
document.body.appendChild(shadowHost); | ||
}); | ||
it('only one `load` event when link is loaded for re-attached element', function(done) { | ||
document.body.appendChild(shadowHost); | ||
enlightedLink.addEventListener('load', loadSpy); | ||
enlightedLink.setAttribute('href', 'assets/doc-with-js.html?2'); | ||
|
||
setTimeout(()=>{ | ||
expect(loadSpy).to.be.calledOnce; | ||
expect(loadSpy.args[0][0].type).to.equal('load'); | ||
done(); | ||
}, 200); | ||
document.body.appendChild(shadowHost); | ||
}); | ||
it('`error` event when link is errored', function(done) { | ||
enlightedLink.addEventListener('error', errorSpy); | ||
enlightedLink.setAttribute('href', 'non-existing.html'); | ||
|
||
setTimeout(()=>{ | ||
expect(errorSpy).to.be.calledOnce; | ||
expect(errorSpy.args[0][0].type).to.equal('error'); | ||
done(); | ||
}, 200); | ||
document.body.appendChild(shadowHost); | ||
}); | ||
it('only one `error` event when link is errored for re-attached element', function(done) { | ||
enlightedLink.setAttribute('href', 'non-existing2.html'); | ||
document.body.appendChild(shadowHost); | ||
enlightedLink.addEventListener('error', errorSpy); | ||
|
||
setTimeout(()=>{ | ||
expect(errorSpy).to.be.calledOnce; | ||
expect(errorSpy.args[0][0].type).to.equal('error'); | ||
done(); | ||
}, 200); | ||
document.body.appendChild(shadowHost); | ||
}); | ||
|
||
}); | ||
</script> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters