From 6999b5c044ed8c7ac668f6b193f23a7c7098c548 Mon Sep 17 00:00:00 2001 From: Bruno Calou Date: Sat, 1 Oct 2022 14:55:48 -0300 Subject: [PATCH] test: add create_out_transition test --- src/runtime/internal/transitions.ts | 2 +- test/dom/index.ts | 2 +- test/transitions/index.ts | 49 +++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 test/transitions/index.ts diff --git a/src/runtime/internal/transitions.ts b/src/runtime/internal/transitions.ts index 93171f071f..7de2ca6b5c 100644 --- a/src/runtime/internal/transitions.ts +++ b/src/runtime/internal/transitions.ts @@ -232,7 +232,7 @@ export function create_out_transition(node: Element & ElementCSSInlineStyle, fn: } return { - end(reset) { + end(reset: boolean) { if (reset && config?.tick) { config.tick(1, 0); } diff --git a/test/dom/index.ts b/test/dom/index.ts index e01e6d17c5..480ffbdc72 100644 --- a/test/dom/index.ts +++ b/test/dom/index.ts @@ -19,7 +19,7 @@ describe('dom', () => { describe('when parentNode does not exist', () => { it('should not throw an exception', () => { const childWithoutParent = document.createElement('div'); - let error = null; + let error: Error | null = null; try { detach(childWithoutParent); diff --git a/test/transitions/index.ts b/test/transitions/index.ts new file mode 100644 index 0000000000..b3ed514b0d --- /dev/null +++ b/test/transitions/index.ts @@ -0,0 +1,49 @@ +import * as assert from 'assert'; +import { create_out_transition, group_outros } from 'svelte/internal'; +import { TransitionConfig } from 'svelte/transition'; + +declare const global: any; + +describe('transitions', () => { + let originalRequestAnimationFrame: () => void; + + before(() => { + originalRequestAnimationFrame = global.requestAnimationFrame; + global.requestAnimationFrame = cb => cb(); + }); + + after(() => { + global.requestAnimationFrame = originalRequestAnimationFrame; + }); + + beforeEach(() => { + group_outros(); + }); + + describe('create_out_transition', () => { + describe('when then transition function returns undefined', () => { + describe('when calling the end function with reset param equals to true', () => { + it('should not throw an exception', () => { + const node = document.createElement('div'); + const transitionConfig: TransitionConfig = { + duration: 0 + }; + const { end } = create_out_transition( + node, + () => undefined, + transitionConfig + ); + let error: Error | null = null; + + try { + end(true); + } catch (e) { + error = e; + } + + assert.equal(error, null); + }); + }); + }); + }); +});