Skip to content

Commit

Permalink
extend dynamic-import tests
Browse files Browse the repository at this point in the history
addresses #3814
  • Loading branch information
gronke committed Oct 30, 2016
1 parent 4be2e44 commit 977a93a
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/unit/dynamic-import.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,42 @@
}, null, true);
});

test('trigger load event of the second request of a resource when loading was not complete yet', function(done) {
Polymer.Base.importHref(url);
Polymer.Base.importHref(url, function() {
done();
});
});

test('trigger load event of the second request of a resource when loading was already completed', function(done) {
var url = 'dynamic-imports/dynamic-lazy.html';
var imprt = Polymer.Base.importHref(url);

var onLoad = function() {
document.removeEventListener('load', onLoad);
Polymer.Base.importHref(url, function() {
done();
});
}

imprt.addEventListener('load', onLoad);
});

test('triggers the callback only once even when the element was requested again later', function(done) {
var count = 0;
Polymer.Base.importHref(url, function() {
count++;
if(count === 1) {
Polymer.Base.importHref(url, function() {
setTimeout(function() {
assert.equal(count, 1, 'the first callback should only be called once');
done();
}, 0);
});
}
});
});

});

});
Expand Down
24 changes: 24 additions & 0 deletions test/unit/dynamic-imports/dynamic-lazy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<link rel="import" href="../../../polymer.html">

<dom-module id="dynamic-lazy">
<template>
<span id="content">dynamic-lazy</span>
</template>
</dom-module>

<script>
Polymer({
is: 'dynamic-lazy'
});
</script>
24 changes: 24 additions & 0 deletions test/unit/dynamic-imports/dynamic-once.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<link rel="import" href="../../../polymer.html">

<dom-module id="dynamic-once">
<template>
<span id="content">dynamic-once</span>
</template>
</dom-module>

<script>
Polymer({
is: 'dynamic-once'
});
</script>

0 comments on commit 977a93a

Please sign in to comment.