|
1 |
| -import test from 'ava'; |
| 1 | +import {describe, it, expect} from 'vitest'; |
2 | 2 | import g from '.';
|
3 | 3 |
|
4 |
| -test('throw error if wrong gradient arguments', t => { |
5 |
| - t.throws(() => g()('abc')); |
6 |
| - t.throws(() => g('red')('abc')); |
7 |
| -}); |
8 |
| - |
9 |
| -test('do not throw error if nothing to color', t => { |
10 |
| - t.is(g('gold', 'silver')(), ''); |
11 |
| - t.is(g('gold', 'silver')(null), ''); |
12 |
| -}); |
13 |
| - |
14 |
| -test('throw error if options is not an object', t => { |
15 |
| - t.throws(() => g('blue', 'red')('abc', false), null, 'Expected `options` to be an `object`, got `boolean`'); |
16 |
| -}); |
17 |
| - |
18 |
| -test('throw error if interpolation is not a string', t => { |
19 |
| - t.throws(() => g('blue', 'red')('abc', {interpolation: 1000}), null, 'Expected `options.interpolation` to be a `string`, got `number`'); |
20 |
| -}); |
21 |
| - |
22 |
| -test('throw error if hsvSpin is not a string, but only if interpolation is HSV', t => { |
23 |
| - t.notThrows(() => g('blue', 'red')('abc', {hsvSpin: 42})); |
24 |
| - t.throws(() => g('blue', 'red')('abc', {interpolation: 'hsv', hsvSpin: 42}), null, 'Expected `options.hsvSpin` to be a `string`, got `number`'); |
25 |
| -}); |
26 |
| - |
27 |
| -test('works fine', t => { |
28 |
| - t.not(g('blue', 'white', 'red')('abc'), 'abc'); |
29 |
| - |
30 |
| - // Red -> yellow -> green (short arc) |
31 |
| - t.not(g('red', 'green')('abc'), g('red', 'green')('abc', {interpolation: 'hsv'})); |
32 |
| - |
33 |
| - // Red -> blue -> green (long arc) |
34 |
| - t.not(g('red', 'green')('abc'), g('red', 'green')('abc', {interpolation: 'hsv', hsvSpin: 'long'})); |
35 |
| - t.not(g('red', 'green')('abc', {interpolation: 'hsv'}), g('red', 'green')('abc', {interpolation: 'hsv', hsvSpin: 'long'})); |
36 |
| -}); |
37 |
| - |
38 |
| -test('varargs syntax equal to array syntax', t => { |
39 |
| - t.is(g('yellow', 'green')('abc'), g(['yellow', 'green'])('abc')); |
40 |
| -}); |
41 |
| - |
42 |
| -test('supports aliases', t => { |
43 |
| - t.is(g.cristal('Hello world'), g('#bdfff3', '#4ac29a')('Hello world')); |
44 |
| - t.is(g.pastel('Hello world'), g('#74ebd5', '#74ecd5')('Hello world', {interpolation: 'hsv', hsvSpin: 'long'})); |
45 |
| -}); |
46 |
| - |
47 |
| -test('multiline option works the same way on one line strings', t => { |
48 |
| - t.is(g('blue', 'white', 'red').multiline('abc'), g('blue', 'white', 'red')('abc')); |
49 |
| - t.is(g('red', 'green').multiline('abc', {interpolation: 'hsv'}), g('red', 'green')('abc', {interpolation: 'hsv'})); |
50 |
| -}); |
51 |
| - |
52 |
| -test('multiline option works fine', t => { |
53 |
| - t.is(g('orange', 'purple').multiline('hello\nworld'), g('orange', 'purple')('hello') + '\n' + g('orange', 'purple')('world')); |
54 |
| - t.is(g.atlas.multiline('abc\n\ndef'), g.atlas('abc') + '\n\n' + g.atlas('def')); |
55 |
| - t.not(g.rainbow.multiline('hi\nworld'), g.rainbow('hi') + '\n' + g.rainbow('world')); |
56 |
| -}); |
57 |
| - |
58 |
| -test('case insensitive options', t => { |
59 |
| - t.is(g('red', 'green')('abc', {interpolation: 'hsv', hsvSpin: 'long'}), g('red', 'green')('abc', {interpolation: 'HSV', hsvSpin: 'Long'})); |
| 4 | +describe('Gradient Tests', () => { |
| 5 | + it('should throw an error if wrong gradient arguments are passed', () => { |
| 6 | + expect(() => g()('abc')).toThrow(); |
| 7 | + expect(() => g('red')('abc')).toThrow(); |
| 8 | + }); |
| 9 | + |
| 10 | + it('should not throw an error if there is nothing to color', () => { |
| 11 | + expect(g('gold', 'silver')()).toBe(''); |
| 12 | + expect(g('gold', 'silver')(null)).toBe(''); |
| 13 | + }); |
| 14 | + |
| 15 | + it('should throw an error if options is not an object', () => { |
| 16 | + expect(() => g('blue', 'red')('abc', false)).toThrowError('Expected `options` to be an `object`, got `boolean`'); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should throw an error if interpolation is not a string', () => { |
| 20 | + expect(() => g('blue', 'red')('abc', {interpolation: 1000})).toThrowError('Expected `options.interpolation` to be a `string`, got `number`'); |
| 21 | + }); |
| 22 | + |
| 23 | + it('should throw an error if hsvSpin is not a string, but only if interpolation is HSV', () => { |
| 24 | + expect(() => g('blue', 'red')('abc', {hsvSpin: 42})).not.toThrow(); |
| 25 | + expect(() => g('blue', 'red')('abc', {interpolation: 'hsv', hsvSpin: 42})).toThrowError('Expected `options.hsvSpin` to be a `string`, got `number`'); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should work correctly with different gradient and interpolation options', () => { |
| 29 | + expect(g('blue', 'white', 'red')('abc')).not.toBe('abc'); |
| 30 | + |
| 31 | + // Red -> yellow -> green (short arc) |
| 32 | + expect(g('red', 'green')('abc')).not.toBe(g('red', 'green')('abc', {interpolation: 'hsv'})); |
| 33 | + |
| 34 | + // Red -> blue -> green (long arc) |
| 35 | + expect(g('red', 'green')('abc')).not.toBe(g('red', 'green')('abc', {interpolation: 'hsv', hsvSpin: 'long'})); |
| 36 | + expect(g('red', 'green')('abc', {interpolation: 'hsv'})).not.toBe(g('red', 'green')('abc', {interpolation: 'hsv', hsvSpin: 'long'})); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should support varargs syntax equal to array syntax', () => { |
| 40 | + expect(g('yellow', 'green')('abc')).toBe(g(['yellow', 'green'])('abc')); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should support aliases', () => { |
| 44 | + expect(g.cristal('Hello world')).toBe(g('#bdfff3', '#4ac29a')('Hello world')); |
| 45 | + expect(g.pastel('Hello world')).toBe(g('#74ebd5', '#74ecd5')('Hello world', {interpolation: 'hsv', hsvSpin: 'long'})); |
| 46 | + }); |
| 47 | + |
| 48 | + it('multiline option should work the same way on one-line strings', () => { |
| 49 | + expect(g('blue', 'white', 'red').multiline('abc')).toBe(g('blue', 'white', 'red')('abc')); |
| 50 | + expect(g('red', 'green').multiline('abc', {interpolation: 'hsv'})).toBe(g('red', 'green')('abc', {interpolation: 'hsv'})); |
| 51 | + }); |
| 52 | + |
| 53 | + it('multiline option should work correctly', () => { |
| 54 | + expect(g('orange', 'purple').multiline('hello\nworld')).toBe(g('orange', 'purple')('hello') + '\n' + g('orange', 'purple')('world')); |
| 55 | + expect(g.atlas.multiline('abc\n\ndef')).toBe(g.atlas('abc') + '\n\n' + g.atlas('def')); |
| 56 | + expect(g.rainbow.multiline('hi\nworld')).not.toBe(g.rainbow('hi') + '\n' + g.rainbow('world')); |
| 57 | + }); |
| 58 | + |
| 59 | + it('case-insensitive options should work correctly', () => { |
| 60 | + expect(g('red', 'green')('abc', {interpolation: 'hsv', hsvSpin: 'long'})).toBe(g('red', 'green')('abc', {interpolation: 'HSV', hsvSpin: 'Long'})); |
| 61 | + }); |
60 | 62 | });
|
0 commit comments