UNPKG

2.11 kBJavaScriptView Raw
1import { values } from 'ramda';
2import camelcase from 'camelcase';
3import { LINEAR_FEATURES } from '../features';
4import featureValues from './featureValues';
5import { mqWithValidBreakpointsForRange } from './data';
6import cssSerialiser from './helpers/cssSerialiser';
7
8expect.addSnapshotSerializer(cssSerialiser);
9
10describe('linear features', () => {
11 const testLinearFeature = (
12 name,
13 validValuesMap,
14 invalidValues,
15 { allowNoArgument = false } = {}
16 ) => {
17 const validValues = values(validValuesMap);
18 const methodName = camelcase(name);
19 describe(`${methodName}()`, () => {
20 describe('linear feature', () => {
21 if (allowNoArgument) {
22 it("doesn't throw if no argument is supplied", () => {
23 expect(() =>
24 mqWithValidBreakpointsForRange('width')[methodName]()
25 ).not.toThrow();
26 });
27
28 it(`returns a valueless ${name}`, () => {
29 expect(
30 mqWithValidBreakpointsForRange('width')[methodName]()
31 ).toMatchSnapshot();
32 });
33 } else {
34 it('throws if no argument is supplied', () => {
35 expect(() =>
36 mqWithValidBreakpointsForRange('width')[methodName]()
37 ).toThrowErrorMatchingSnapshot();
38 });
39 }
40
41 for (const value of invalidValues) {
42 it(`throws if argument is '${value}'`, () => {
43 expect(() =>
44 mqWithValidBreakpointsForRange('width')[methodName](value)
45 ).toThrowErrorMatchingSnapshot();
46 });
47 }
48 for (const value of validValues) {
49 it(`returns the supplied ${name} for '${value}'`, () => {
50 expect(
51 mqWithValidBreakpointsForRange('width')[methodName](value)
52 ).toMatchSnapshot();
53 });
54 }
55 });
56 });
57 };
58
59 for (const feature of LINEAR_FEATURES) {
60 const { name, validValues, allowNoArgument } = feature;
61 const { invalidValues } = featureValues(camelcase(name));
62 testLinearFeature(name, validValues, invalidValues, { allowNoArgument });
63 }
64});