Skip to content

Commit

Permalink
Refactor lib/__tests__/ignoreDisables.test.js (#5283)
Browse files Browse the repository at this point in the history
This change aims to improve the test code readability via async/await syntax.
(avoiding callbacks as much possible)

See also <jestjs.io/docs/asynchronous>
  • Loading branch information
ybiquitous committed May 12, 2021
1 parent e63f1c7 commit 463c8e8
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions lib/__tests__/ignoreDisables.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,31 @@

const postcssPlugin = require('../postcssPlugin');
const standalone = require('../standalone');
const stripIndent = require('common-tags').stripIndent;

const config = {
rules: { 'block-no-empty': true },
};

const css = stripIndent`
/* stylelint-disable */
a {}
/* stylelint-enable */
a {
b {} /* stylelint-disable-line block-no-empty */
}`;
const css = `
/* stylelint-disable */
a {}
/* stylelint-enable */
a {
b {} /* stylelint-disable-line block-no-empty */
}`;

describe('ignoreDisables with postcssPlugins', () => {
let result;

beforeEach(() => {
return postcssPlugin
.process(
css,
{ from: undefined },
{
config,
ignoreDisables: true,
},
)
.then((data) => (result = data));
beforeEach(async () => {
result = await postcssPlugin.process(
css,
{ from: undefined },
{
config,
ignoreDisables: true,
},
);
});

it('expected number of warnings', () => {
Expand All @@ -48,12 +45,14 @@ describe('ignoreDisables with postcssPlugins', () => {
describe('ignoreDisables with standalone', () => {
let results;

beforeEach(() => {
return standalone({
config,
code: css,
ignoreDisables: true,
}).then((data) => (results = data.results));
beforeEach(async () => {
results = (
await standalone({
config,
code: css,
ignoreDisables: true,
})
).results;
});

it('expected number of warnings', () => {
Expand All @@ -72,11 +71,13 @@ describe('ignoreDisables with standalone', () => {
describe('ignoreDisables with config', () => {
let results;

beforeEach(() => {
return standalone({
config: { ignoreDisables: true, ...config },
code: css,
}).then((data) => (results = data.results));
beforeEach(async () => {
results = (
await standalone({
config: { ignoreDisables: true, ...config },
code: css,
})
).results;
});

it('expected number of warnings', () => {
Expand Down

0 comments on commit 463c8e8

Please sign in to comment.