Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

stylelint-jest-rule-tester

electrovir387MIT2.1.7TypeScript support: included

Simple stylelint.io rule tester that uses Jest.

stylelint, jest, rule, test, style, lint, css, less, scss, sass

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,
        },
    ],
});