-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathHexColorCode.test.ts
58 lines (51 loc) · 1.75 KB
/
HexColorCode.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* global describe, it, expect */
import { Kind } from 'graphql/language';
import { GraphQLHexColorCode } from '../src/scalars/HexColorCode.js';
describe(`HexColorCode`, () => {
describe(`valid`, () => {
it(`serialize`, () => {
expect(GraphQLHexColorCode.serialize(`#BadA55`)).toEqual(`#BadA55`);
});
it(`parseValue`, () => {
expect(GraphQLHexColorCode.parseValue(`#BadA55`)).toEqual(`#BadA55`);
});
it(`parseLiteral`, () => {
expect(
GraphQLHexColorCode.parseLiteral(
{
value: `#BadA55`,
kind: Kind.STRING,
},
{},
),
).toEqual(`#BadA55`);
});
});
describe(`invalid`, () => {
describe(`not a valid HexColorCode`, () => {
it(`serialize`, () => {
expect(() => GraphQLHexColorCode.serialize(123)).toThrow(/Value is not string/);
expect(() => GraphQLHexColorCode.serialize(`this is not a hex color code`)).toThrow(
/Value is not a valid HexColorCode/,
);
});
it(`parseValue`, () => {
expect(() => GraphQLHexColorCode.serialize(123)).toThrow(/Value is not string/);
expect(() => GraphQLHexColorCode.parseValue(`this is not a hex color code`)).toThrow(
/Value is not a valid HexColorCode/,
);
});
it(`parseLiteral`, () => {
expect(() =>
GraphQLHexColorCode.parseLiteral({ value: 123, kind: Kind.INT } as any, {}),
).toThrow(/Can only validate strings as hex color codes but got a/);
expect(() =>
GraphQLHexColorCode.parseLiteral(
{ value: `this is not a hex color code`, kind: Kind.STRING },
{},
),
).toThrow(/Value is not a valid HexColorCode/);
});
});
});
});