Files
shaka-player/test/util/lazy_unit.js
T
Wojciech Tyczyński e0a57bb27d fix: Make shaka.util.Lazy work with null (#8267)
Due to usage of `==` instead of `===` Lazy utility does not work
correctly with null generators, despite of what is stated in
documentation.
2025-03-13 17:10:37 +01:00

34 lines
1.1 KiB
JavaScript

/*! @license
* Shaka Player
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
describe('Lazy', () => {
it('returns the same object each time', () => {
const generator = jasmine.createSpy('generator').and.returnValue({});
const lazy = new shaka.util.Lazy(shaka.test.Util.spyFunc(generator));
const value = lazy.value();
const value2 = lazy.value();
expect(value).toBe(value2);
expect(generator).toHaveBeenCalledTimes(1);
});
it('works correctly for primitive value', () => {
const generator = jasmine.createSpy('generator').and.returnValue(7);
const lazy = new shaka.util.Lazy(shaka.test.Util.spyFunc(generator));
const value = lazy.value();
const value2 = lazy.value();
expect(value).toBe(value2);
expect(generator).toHaveBeenCalledTimes(1);
});
it('works correctly for null', () => {
const generator = jasmine.createSpy('generator').and.returnValue(null);
const lazy = new shaka.util.Lazy(shaka.test.Util.spyFunc(generator));
const value = lazy.value();
expect(value).toBe(null);
expect(generator).toHaveBeenCalledTimes(1);
});
});