From 14877b536e32e3f5de5423c66e1ed6dc9d672084 Mon Sep 17 00:00:00 2001 From: Bruno Calou Date: Sat, 1 Oct 2022 15:08:07 -0300 Subject: [PATCH] test: improve create_out_transition tests --- test/transitions/index.ts | 65 +++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/test/transitions/index.ts b/test/transitions/index.ts index b3ed514b0d..c5d40800e2 100644 --- a/test/transitions/index.ts +++ b/test/transitions/index.ts @@ -5,43 +5,62 @@ import { TransitionConfig } from 'svelte/transition'; declare const global: any; describe('transitions', () => { - let originalRequestAnimationFrame: () => void; + let originalRequestAnimationFrame: () => void; - before(() => { - originalRequestAnimationFrame = global.requestAnimationFrame; - global.requestAnimationFrame = cb => cb(); - }); + before(() => { + originalRequestAnimationFrame = global.requestAnimationFrame; + global.requestAnimationFrame = (cb) => cb(); + }); + + after(() => { + global.requestAnimationFrame = originalRequestAnimationFrame; + }); - after(() => { - global.requestAnimationFrame = originalRequestAnimationFrame; - }); + beforeEach(() => { + group_outros(); + }); - beforeEach(() => { - group_outros(); - }); - describe('create_out_transition', () => { - describe('when then transition function returns undefined', () => { + describe('when then transition function does not return a tick function', () => { describe('when calling the end function with reset param equals to true', () => { it('should not throw an exception', () => { + const noTickConfigs: TransitionConfig[] = [undefined, null, {}]; + + noTickConfigs.forEach((config) => { + const node = document.createElement('div'); + const { end } = create_out_transition(node, () => config, {}); + let error: Error | null = null; + + try { + end(true); + } catch (e) { + error = e; + } + + assert.equal(error, null); + }); + }); + }); + }); + + describe('when the transition function returns a config object with defined tick function', () => { + describe('when calling the end function with reset param equals to true', () => { + it('should call the tick function', () => { const node = document.createElement('div'); + let tick = 0; const transitionConfig: TransitionConfig = { - duration: 0 + duration: 0, + tick: () => (tick += 1) }; const { end } = create_out_transition( node, - () => undefined, - transitionConfig + () => transitionConfig, + {} ); - let error: Error | null = null; - try { - end(true); - } catch (e) { - error = e; - } + end(true); - assert.equal(error, null); + assert.equal(tick, 1); }); }); });