eslint-plugin-vanilla-extract/src/css-rules/shared-utils/__tests__/property-name-extractor.test.ts
Ante Budimir 1092b47f1c test : add coverage for shared utility functions
Add comprehensive tests for shared utility modules to improve code coverage:

- Test property name extraction edge cases
- Test CSS property priority map with invalid groups
- Test order strategy visitor creator edge cases
- Test font face property order enforcer early returns
- Test style node processor with arrays and null values

These tests ensure all code paths in shared utilities are properly exercised,
including error handling and edge cases.
2025-03-10 09:28:51 +02:00

57 lines
1.4 KiB
TypeScript

import tsParser from '@typescript-eslint/parser';
import { run } from 'eslint-vitest-rule-tester';
import testRuleForPropertyNameExtractor from './test-property-name-rule.js';
run({
name: 'vanilla-extract/property-name-extractor-tests',
rule: testRuleForPropertyNameExtractor,
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
},
},
valid: [
// Test for identifier and string literal keys (should return names)
`
import { style } from '@vanilla-extract/css';
const myStyle = style({
color: 'blue',
'background-color': 'white',
fontSize: '16px'
});
`,
// Test for computed property with non-string literal (should return empty string)
`
import { style } from '@vanilla-extract/css';
const myStyle = style({
[42]: 'numeric key',
[true]: 'boolean key'
});
`,
// Test for computed property with complex expression
`
import { style } from '@vanilla-extract/css';
const myStyle = style({
[Math.random() > 0.5 ? 'dynamicKey' : 'otherKey']: 'dynamic value'
});
`,
// Test for property with template literal key
`
import { style } from '@vanilla-extract/css';
const prefix = 'webkit';
const myStyle = style({
[\`-\${prefix}-appearance\`]: 'none'
});
`,
],
invalid: [],
});