From 2efbeca70cb027bc190a10f9f9fa149fad8495e9 Mon Sep 17 00:00:00 2001 From: Bart Veneman Date: Mon, 30 Mar 2026 19:51:11 +0200 Subject: [PATCH] chore: add test for minifying nth selectors --- test/selectors.test.ts | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/test/selectors.test.ts b/test/selectors.test.ts index 05d9c86..d172f47 100644 --- a/test/selectors.test.ts +++ b/test/selectors.test.ts @@ -117,21 +117,30 @@ d::first-letter {}` expect(actual).toEqual(expected) }) -test('formats selectors with Nth', () => { - let fixtures = [ - [`li:nth-child(3n-2) {}`, `li:nth-child(3n -2) {}`], - [`li:nth-child(0n+1) {}`, `li:nth-child(0n + 1) {}`], - [`li:nth-child(even of .noted) {}`, `li:nth-child(even of .noted) {}`], - [`li:nth-child(2n of .noted) {}`, `li:nth-child(2n of .noted) {}`], - [`li:nth-child(-n + 3 of .noted) {}`, `li:nth-child(-n + 3 of .noted) {}`], - [`li:nth-child(-n+3 of li.important) {}`, `li:nth-child(-n + 3 of li.important) {}`], - [`p:nth-child(n+8):nth-child(-n+15) {}`, `p:nth-child(n + 8):nth-child(-n + 15) {}`], - ] +test.each([ + [`li:nth-child(3n-2) {}`, `li:nth-child(3n -2) {}`], + [`li:nth-child(0n+1) {}`, `li:nth-child(0n + 1) {}`], + [`li:nth-child(even of .noted) {}`, `li:nth-child(even of .noted) {}`], + [`li:nth-child(2n of .noted) {}`, `li:nth-child(2n of .noted) {}`], + [`li:nth-child(-n + 3 of .noted) {}`, `li:nth-child(-n + 3 of .noted) {}`], + [`li:nth-child(-n+3 of li.important) {}`, `li:nth-child(-n + 3 of li.important) {}`], + [`p:nth-child(n+8):nth-child(-n+15) {}`, `p:nth-child(n + 8):nth-child(-n + 15) {}`], +])('formats nth selector: %s', (css, expected) => { + let actual = format(css) + expect(actual).toEqual(expected) +}) - for (let [css, expected] of fixtures) { - let actual = format(css) - expect(actual).toEqual(expected) - } +test.each([ + [`li:nth-child(3n-2) {}`, `li:nth-child(3n-2){}`], + [`li:nth-child(0n+1) {}`, `li:nth-child(0n+1){}`], + [`li:nth-child(even of .noted) {}`, `li:nth-child(even of .noted){}`], + [`li:nth-child(2n of .noted) {}`, `li:nth-child(2n of .noted){}`], + [`li:nth-child(-n + 3 of .noted) {}`, `li:nth-child(-n+3 of .noted){}`], + [`li:nth-child(-n+3 of li.important) {}`, `li:nth-child(-n+3 of li.important){}`], + [`p:nth-child(n+8):nth-child(-n+15) {}`, `p:nth-child(n+8):nth-child(-n+15){}`], +])('minifies nth selector: %s', (css, expected) => { + let actual = format(css, { minify: true }) + expect(actual).toEqual(expected) }) test('formats multiline selectors', () => {