pwa-helpers
Version:
Small helper methods or mixins to help you build web apps.
53 lines (46 loc) • 1.85 kB
HTML
<!--
@license
Copyright (c) 2018 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
-->
<html lang="en">
<head>
<meta charset="utf-8">
<title>network</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="../node_modules/chai/chai.js"></script>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/wct-mocha/wct-mocha.js"></script>
</head>
<body>
<script type="module">
import sinon from 'sinon';
import { installOfflineWatcher } from '../network.js';
const firstCallback = sinon.spy();
let callback = firstCallback;
installOfflineWatcher((offline) => callback(offline));
suite('network tests', () => {
setup(() => {
callback = sinon.spy();
});
test('installation should use callback', () => {
assert.isTrue(firstCallback.called);
assert.equal(firstCallback.lastCall.args[0], !navigator.onLine);
});
test('online event should use callback', () => {
window.dispatchEvent(new CustomEvent('online'));
assert.isFalse(callback.lastCall.args[0]);
});
test('offline event should use callback', () => {
window.dispatchEvent(new CustomEvent('offline'));
assert.isTrue(callback.lastCall.args[0]);
});
});
</script>
</body>
</html>