Files
Jeffrey PosnickandGitHub 7d4c4434a4 Enable prettier (#2929)
* Deps and config

* Prettier output

* Update hardcoded file sizes

* More file size updates
2021-08-26 14:57:20 -07:00

70 lines
2.1 KiB
JavaScript

/*
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 {CacheableResponse} from 'workbox-cacheable-response/CacheableResponse.mjs';
import {CacheableResponsePlugin} from 'workbox-cacheable-response/CacheableResponsePlugin.mjs';
describe(`CacheableResponsePlugin`, function () {
const STATUSES = [200];
const sandbox = sinon.createSandbox();
beforeEach(function () {
sandbox.restore();
});
after(function () {
sandbox.restore();
});
describe(`constructor`, function () {
it(`should construct a properly-configured internal CacheableResponse instance`, function () {
const cacheableResponsePlugin = new CacheableResponsePlugin({
statuses: STATUSES,
});
expect(cacheableResponsePlugin._cacheableResponse).to.be.instanceOf(
CacheableResponse,
);
expect(cacheableResponsePlugin._cacheableResponse._statuses).to.eql(
STATUSES,
);
});
it(`should expose cacheWillUpdate, which calls cacheableResponse.isResponseCacheable()`, function () {
const cacheableResponsePlugin = new CacheableResponsePlugin({
statuses: STATUSES,
});
const isResponseCacheableSpy = sandbox.spy(
cacheableResponsePlugin._cacheableResponse,
'isResponseCacheable',
);
const response = new Response('');
cacheableResponsePlugin.cacheWillUpdate({response});
expect(isResponseCacheableSpy.calledOnce).to.be.true;
expect(isResponseCacheableSpy.calledWithExactly(response)).to.be.true;
});
});
describe(`cacheWillUpdate`, function () {
it(`should return null for non-cachable response`, async function () {
const cacheableResponsePlugin = new CacheableResponsePlugin({
statuses: STATUSES,
});
sandbox
.stub(cacheableResponsePlugin._cacheableResponse, 'isResponseCacheable')
.callsFake(() => false);
expect(
await cacheableResponsePlugin.cacheWillUpdate({
response: new Response(),
}),
).to.equal(null);
});
});
});