]>
git.r.bdr.sh - rbdr/forum/blob - src/animations/blink.test.js
1 import { blink
} from './blink';
2 import { sineOut
} from 'svelte/easing';
8 describe('blink', () => {
10 test('it has a default delay of 0ms', () => {
12 const response
= blink(document
.createElement('div'), {});
14 expect(response
.delay
).toBe(0);
17 test('it allows delay to be overridden', () => {
19 const response
= blink(document
.createElement('div'), {
23 expect(response
.delay
).toBe(300);
26 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', () => {
35 const response
= blink(document
.createElement('div'), {
39 expect(response
.duration
).toBe(999);
42 test('it uses sineOut as the default easing function', () => {
44 const response
= blink(document
.createElement('div'), {});
46 expect(response
.easing
).toBe(sineOut
);
49 test('it allows easing function to be overridden', () => {
51 const response
= blink(document
.createElement('div'), {
52 easing: () => 'excellent'
55 expect(response
.easing()).toBe('excellent');
58 describe('css animation function', () => {
62 const div
= document
.createElement('div');
63 div
.style
.width
= '100px';
64 div
.style
.height
= '200px';
65 internals
.response
= blink(div
, {});
68 test('It starts with with zeroed width and height', () => {
70 const css
= internals
.response
.css(0, 1);
71 expect(css
).toContain('width: 0px');
72 expect(css
).toContain('height: 0px');
75 test('It grows to full height and 0 width in first 20%', () => {
77 const css
= internals
.response
.css(0.2, 0.8);
78 expect(css
).toContain('width: 0px');
79 expect(css
).toContain('height: 200px');
82 test('It expands to full height by the end', () => {
84 const css
= internals
.response
.css(1, 0);
85 expect(css
).toContain('width: 100px');
86 expect(css
).toContain('height: 200px');
89 test('It keeps element vertically centered by adjusting the margin', () => {
91 const css
= internals
.response
.css(0.1, 0.9);
92 expect(css
).toContain('margin: 50px 50px');
93 expect(css
).toContain('height: 100px');
96 test('It keeps element horizontally centered by adjusting the margin', () => {
98 const css
= internals
.response
.css(0.6, 0.4);
99 expect(css
).toContain('margin: 0px 25px');
100 expect(css
).toContain('width: 50px');