Skip to content

Commit 2ba1cb3

Browse files
committed
Add tests for custom string and length generic
1 parent 2bf4e9c commit 2ba1cb3

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

__fixtures__/typecheck.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@ import * as CSS from '../index.js.flow';
44
const css: CSS.Properties<*> = {
55
flexGrow: 1,
66
flexShrink: 1,
7-
flexBasis: '1px',
7+
flexBasis: 'max-content',
88
flexDirection: 'row',
99
MozAppearance: 'button',
1010
msOverflowStyle: 'scrollbar',
11+
12+
// Test custom string
13+
borderBottomWidth: 'calc(1px)',
14+
// This property has `TLength` (but not `(string & {})` itself) so
15+
// if this fails it may have something to do with default generic values
16+
borderBottomWidth: 'calc(1px)',
1117
};
1218

1319
const cssWithFallbackValues: CSS.PropertiesFallback<*> = {
1420
flexGrow: [1],
1521
flexShrink: [1],
16-
flexBasis: ['1px'],
22+
flexBasis: ['max-content'],
1723
flexDirection: ['row'],
1824
MozAppearance: ['button'],
1925
msOverflowStyle: ['scrollbar'],
@@ -22,12 +28,16 @@ const cssWithFallbackValues: CSS.PropertiesFallback<*> = {
2228
const cssWithHyphenProperties: CSS.PropertiesHyphen<*> = {
2329
'flex-grow': 1,
2430
'flex-shrink': 0,
25-
'flex-basis': '1px',
31+
'flex-basis': 'max-content',
2632
'flex-direction': 'row',
2733
'-moz-appearance': 'button',
2834
'-ms-overflow-style': 'scrollbar',
2935
};
3036

37+
const cssWithDifferentLength: CSS.Properties<{ px: number }> = {
38+
width: { px: 1 },
39+
};
40+
3141
const unknownProperty: CSS.Properties<*> = {
3242
unknownProperty: 1,
3343
};

__fixtures__/typecheck.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@ import * as CSS from '..';
55
const css: CSS.Properties = {
66
flexGrow: 1,
77
flexShrink: 1,
8-
flexBasis: '1px',
8+
flexBasis: 'max-content',
99
flexDirection: 'row',
1010
MozAppearance: 'button',
1111
msOverflowStyle: 'scrollbar',
12+
13+
// Test custom string to make sure `(string & {})` haven't broken
14+
width: 'calc(1px)',
15+
// This property has `TLength` (but not `(string & {})` itself) so
16+
// if this fails it may have something to do with default generic values
17+
borderBottomWidth: 'calc(1px)',
1218
};
1319

1420
const cssWithFallbackValues: CSS.PropertiesFallback = {
1521
flexGrow: [1],
1622
flexShrink: [1],
17-
flexBasis: ['1px'],
23+
flexBasis: ['max-content'],
1824
flexDirection: ['row'],
1925
MozAppearance: ['button'],
2026
msOverflowStyle: ['scrollbar'],
@@ -23,12 +29,16 @@ const cssWithFallbackValues: CSS.PropertiesFallback = {
2329
const cssWithHyphenProperties: CSS.PropertiesHyphen = {
2430
'flex-grow': 1,
2531
'flex-shrink': 0,
26-
'flex-basis': '1px',
32+
'flex-basis': 'max-content',
2733
'flex-direction': 'row',
2834
'-moz-appearance': 'button',
2935
'-ms-overflow-style': 'scrollbar',
3036
};
3137

38+
const cssWithDifferentLength: CSS.Properties<{ px: number }> = {
39+
width: { px: 1 },
40+
};
41+
3242
const unknownProperty: CSS.Properties = {
3343
unknownProperty: 1,
3444
};
@@ -40,5 +50,6 @@ const cssWithDisallowedFallbackValues: CSS.Properties = {
4050
css;
4151
cssWithFallbackValues;
4252
cssWithHyphenProperties;
53+
cssWithDifferentLength;
4354
unknownProperty;
4455
cssWithDisallowedFallbackValues;
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`it detects errors 1`] = `"31:44 - Cannot assign object literal to \`unknownProperty\` because property \`unknownProperty\` is missing in \`Properties\` [1] but exists in object literal [2]."`;
3+
exports[`it detects errors 1`] = `"41:44 - Cannot assign object literal to \`unknownProperty\` because property \`unknownProperty\` is missing in \`Properties\` [1] but exists in object literal [2]."`;
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`it detects errors 1`] = `
4-
"32:2 - Type '{ unknownProperty: number; }' is not assignable to type 'Properties<0 | (string & {})>'.
4+
"42:2 - Type '{ unknownProperty: number; }' is not assignable to type 'Properties<0 | (string & {})>'.
55
Object literal may only specify known properties, and 'unknownProperty' does not exist in type 'Properties<0 | (string & {})>'."
66
`;
77

88
exports[`it detects errors 2`] = `
9-
"36:2 - Type 'string[]' is not assignable to type '0 | \\"auto\\" | \\"inherit\\" | (string & {}) | \\"-moz-initial\\" | \\"initial\\" | \\"revert\\" | \\"unset\\" | undefined'.
9+
"46:2 - Type 'string[]' is not assignable to type '0 | \\"auto\\" | \\"inherit\\" | (string & {}) | \\"-moz-initial\\" | \\"initial\\" | \\"revert\\" | \\"unset\\" | undefined'.
1010
Type 'string[]' is not assignable to type '\\"unset\\"'."
1111
`;

0 commit comments

Comments
 (0)