2 * @jest-environment jsdom
5 import { blink } from './blink';
6 import { sineOut } from 'svelte/easing';
12 describe('blink', () => {
13 test('it has a default delay of 0ms', () => {
14 const response = blink(document.createElement('div'), {});
16 expect(response.delay).toBe(0);
19 test('it allows delay to be overridden', () => {
20 const response = blink(document.createElement('div'), {
24 expect(response.delay).toBe(300);
27 test('it has a default duration of 400ms', () => {
28 const response = blink(document.createElement('div'), {});
30 expect(response.duration).toBe(400);
33 test('it allows delay to be overridden', () => {
34 const response = blink(document.createElement('div'), {
38 expect(response.duration).toBe(999);
41 test('it uses sineOut as the default easing function', () => {
42 const response = blink(document.createElement('div'), {});
44 expect(response.easing).toBe(sineOut);
47 test('it allows easing function to be overridden', () => {
48 const response = blink(document.createElement('div'), {
52 expect(response.easing(0)).toBe(666);
55 describe('css animation function', () => {
57 const div = document.createElement('div');
58 div.style.width = '100px';
59 div.style.height = '200px';
60 internals.response = blink(div, {});
63 test('It starts with with zeroed width and height', () => {
64 const css = internals.response.css(0, 1);
65 expect(css).toContain('width: 0px');
66 expect(css).toContain('height: 0px');
69 test('It grows to full height and 0 width in first 20%', () => {
70 const css = internals.response.css(0.2, 0.8);
71 expect(css).toContain('width: 0px');
72 expect(css).toContain('height: 200px');
75 test('It expands to full height by the end', () => {
76 const css = internals.response.css(1, 0);
77 expect(css).toContain('width: 100px');
78 expect(css).toContain('height: 200px');
81 test('It keeps element vertically centered by adjusting the margin', () => {
82 const css = internals.response.css(0.1, 0.9);
83 expect(css).toContain('margin: 50px 50px');
84 expect(css).toContain('height: 100px');
87 test('It keeps element horizontally centered by adjusting the margin', () => {
88 const css = internals.response.css(0.6, 0.4);
89 expect(css).toContain('margin: 0px 25px');
90 expect(css).toContain('width: 50px');