2 * @jest-environment jsdom
5 import { blink } from './blink';
6 import { sineOut } from 'svelte/easing';
12 describe('blink', () => {
14 test('it has a default delay of 0ms', () => {
16 const response = blink(document.createElement('div'), {});
18 expect(response.delay).toBe(0);
21 test('it allows delay to be overridden', () => {
23 const response = blink(document.createElement('div'), {
27 expect(response.delay).toBe(300);
30 test('it has a default duration of 400ms', () => {
32 const response = blink(document.createElement('div'), {});
34 expect(response.duration).toBe(400);
37 test('it allows delay to be overridden', () => {
39 const response = blink(document.createElement('div'), {
43 expect(response.duration).toBe(999);
46 test('it uses sineOut as the default easing function', () => {
48 const response = blink(document.createElement('div'), {});
50 expect(response.easing).toBe(sineOut);
53 test('it allows easing function to be overridden', () => {
55 const response = blink(document.createElement('div'), {
59 expect(response.easing(0)).toBe(666);
62 describe('css animation function', () => {
66 const div = document.createElement('div');
67 div.style.width = '100px';
68 div.style.height = '200px';
69 internals.response = blink(div, {});
72 test('It starts with with zeroed width and height', () => {
74 const css = internals.response.css(0, 1);
75 expect(css).toContain('width: 0px');
76 expect(css).toContain('height: 0px');
79 test('It grows to full height and 0 width in first 20%', () => {
81 const css = internals.response.css(0.2, 0.8);
82 expect(css).toContain('width: 0px');
83 expect(css).toContain('height: 200px');
86 test('It expands to full height by the end', () => {
88 const css = internals.response.css(1, 0);
89 expect(css).toContain('width: 100px');
90 expect(css).toContain('height: 200px');
93 test('It keeps element vertically centered by adjusting the margin', () => {
95 const css = internals.response.css(0.1, 0.9);
96 expect(css).toContain('margin: 50px 50px');
97 expect(css).toContain('height: 100px');
100 test('It keeps element horizontally centered by adjusting the margin', () => {
102 const css = internals.response.css(0.6, 0.4);
103 expect(css).toContain('margin: 0px 25px');
104 expect(css).toContain('width: 50px');