-
Notifications
You must be signed in to change notification settings - Fork 798
/
test-isSupported.mjs
51 lines (41 loc) 路 1.37 KB
/
test-isSupported.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
Copyright 2018 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/
import {expect} from 'chai';
import clearRequire from 'clear-require';
describe(`[workbox-streams] isSupported`, function() {
const originalReadableStream = global.ReadableStream;
const MODULE_ID = '../../../packages/workbox-streams/isSupported.mjs';
afterEach(function() {
global.ReadableStream = originalReadableStream;
clearRequire(MODULE_ID);
});
it(`should return true when ReadableStream is available`, async function() {
class ReadableStream {
constructor() {
// no-op
}
}
global.ReadableStream = ReadableStream;
const {isSupported} = await import(MODULE_ID);
expect(isSupported()).to.be.true;
});
it(`should return false when ReadableStream is not available`, async function() {
global.ReadableStream = undefined;
const {isSupported} = await import(MODULE_ID);
expect(isSupported()).to.be.false;
});
it(`should return false when ReadableStream throws during construction`, async function() {
class ReadableStream {
constructor() {
throw new Error();
}
}
global.ReadableStream = ReadableStream;
const {isSupported} = await import(MODULE_ID);
expect(isSupported()).to.be.false;
});
});