Warning, /firebird/packages/firebird-ng/display/src/lib/services/render-loop.spec.ts is written in an unsupported language. File is not indexed.
0001 import { runIsolated, shouldRenderFrame } from './render-loop';
0002
0003 describe('shouldRenderFrame', () => {
0004 const clean = [{ dirty: false }, { dirty: false }];
0005
0006 it('stays idle on demand when nothing is dirty', () => {
0007 expect(shouldRenderFrame(false, false, clean)).toBe(false);
0008 expect(shouldRenderFrame(false, false, [])).toBe(false);
0009 });
0010
0011 it('renders on demand after invalidate() or when any one view is dirty', () => {
0012 expect(shouldRenderFrame(false, true, clean)).toBe(true);
0013 expect(shouldRenderFrame(false, false, [{ dirty: false }, { dirty: true }])).toBe(true);
0014 });
0015
0016 it('renders every frame in continuous mode', () => {
0017 expect(shouldRenderFrame(true, false, clean)).toBe(true);
0018 });
0019 });
0020
0021 describe('runIsolated', () => {
0022 it('keeps calling the remaining targets after one throws, and reports the offenders', () => {
0023 const called: string[] = [];
0024 const errors: string[] = [];
0025 const failed = runIsolated(['a', 'bad', 'c', 'worse'],
0026 target => {
0027 called.push(target);
0028 if (target === 'bad' || target === 'worse') throw new Error(target);
0029 },
0030 (target, error) => errors.push(`${target}:${(error as Error).message}`));
0031
0032 expect(called).toEqual(['a', 'bad', 'c', 'worse']);
0033 expect(failed).toEqual(['bad', 'worse']);
0034 expect(errors).toEqual(['bad:bad', 'worse:worse']);
0035 });
0036
0037 it('returns no offenders when every target succeeds', () => {
0038 expect(runIsolated([1, 2, 3], () => undefined, () => { throw new Error('unreachable'); })).toEqual([]);
0039 });
0040 });