Skip to content
Snippets Groups Projects
Select Git revision
  • 2462951254be02d112b2716fdcca2821b321cbd9
  • master default protected
  • gh-pages
  • dependabot/npm_and_yarn/eslint-plugin-jsdoc-51.0.3
  • dependabot/npm_and_yarn/nock-14.0.5
  • dependabot/npm_and_yarn/react-19.1.0
  • dependabot/npm_and_yarn/react-dom-19.1.0
  • server-2025-02-01-6100669a
  • server-2024-11-01-87cba042
  • server-2024-10-01-6875b7c8
  • dependabot/npm_and_yarn/path-to-regexp-8.2.0
  • server-2024-09-01-3d52575c
  • daily-tests-gha2
  • daily-tests-gha
  • server-2023-12-01-92d8fb8e
  • server-2023-11-01-a80c93fd
  • server-2023-10-01-31096085
  • coc-v2
  • server-2023-09-01-8edc3810
  • server-2023-08-01-75858a03
  • server-2023-07-01-02183d8d
  • 5.0.2
  • 5.0.1
  • 5.0.0
  • server-2025-06-01
  • server-2025-05-01
  • server-2025-04-03
  • server-2025-03-02
  • server-2025-03-01
  • server-2025-02-02
  • server-2025-01-01
  • server-2024-12-01
  • server-2024-11-02
  • 4.1.0
  • server-2024-09-25
  • server-2024-09-02
  • server-2024-08-01
  • server-2024-07-01
  • 4.0.0
  • server-2024-06-01
  • server-2024-05-01
41 results

entrypoint.spec.js

Blame
  • lazy.spec.ts 1.68 KiB
    import { Lazy } from './lazy';
    
    describe('util/lazy', () => {
      describe('.getValue()', () => {
        it('gets a value', () => {
          const spy = jest.fn().mockReturnValue(0);
          const lazy = new Lazy(() => spy());
          const value = lazy.getValue();
          expect(value).toBe(0);
          expect(spy).toHaveBeenCalledTimes(1);
        });
    
        it('caches the value', () => {
          const spy = jest.fn().mockReturnValue(0);
          const lazy = new Lazy(() => spy());
          lazy.getValue();
          lazy.getValue();
          expect(spy).toHaveBeenCalledTimes(1);
        });
    
        it('throws an error', () => {
          const spy = jest.fn().mockImplementation(() => {
            throw new Error();
          });
          const lazy = new Lazy(() => spy());
          expect(() => lazy.getValue()).toThrow();
          expect(spy).toHaveBeenCalledTimes(1);
        });
    
        it('caches the error', () => {
          const spy = jest.fn().mockImplementation(() => {
            throw new Error();
          });
          const lazy = new Lazy(() => spy());
          expect(() => lazy.getValue()).toThrow();
          expect(() => lazy.getValue()).toThrow();
          expect(spy).toHaveBeenCalledTimes(1);
        });
      });
    
      describe('.hasValue()', () => {
        it('has a value', () => {
          const spy = jest.fn().mockReturnValue(0);
          const lazy = new Lazy(() => spy());
          lazy.getValue();
          const hasValue = lazy.hasValue();
          expect(hasValue).toBeTrue();
          expect(spy).toHaveBeenCalledTimes(1);
        });
    
        it('does not have a value', () => {
          const spy = jest.fn().mockReturnValue(0);
          const lazy = new Lazy(() => spy());
          const hasValue = lazy.hasValue();
          expect(hasValue).toBeFalse();
          expect(spy).toHaveBeenCalledTimes(0);
        });
      });
    });