stylelint-jest-rule-tester

Simple stylelint.io rule tester that uses Jest.

Usage no npm install needed!

<script type="module">
  import stylelintJestRuleTester from 'https://cdn.skypack.dev/stylelint-jest-rule-tester';
</script>

README

Stylelint Jest Rule Tester

This is not an official stylelint package.

tests

Simple function written in TypeScript to test custom stylelint plugin rules.

Largely influenced by jest-preset-stylelint/getTestRule.js.

Usage

This is from this project's test file.

import {testRule} from 'stylelint-jest-rule-tester';
import {visibilityRule} from './visibility.rule';

testRule({
    // replace this name with your rule's name
    ruleName: visibilityRule.ruleName,
    description: 'should work primary option in array',
    ruleOptions: [true],
    // a plugin must be supplied so that stylelint can find the rule you want to test
    linterOptions: {config: {plugins: ['./dist/test/plugins.js']}},
    fix: true,
    accept: [
        {
            code: 'a { color: pink; }',
        },
    ],
    reject: [
        {
            code: 'a { color: pink; visibility: hidden; }',
            fixed: 'a { color: pink; }',
            message: visibilityRule.message,
        },
    ],
});