From 9aa1c8e80e055a196b55e4522ea2d733cbdf31e5 Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Sun, 7 Jul 2024 18:05:54 +0200 Subject: [PATCH] add tests for experimentalParseClassName --- tests/experimental-parse-class-name.test.ts | 37 +++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/experimental-parse-class-name.test.ts diff --git a/tests/experimental-parse-class-name.test.ts b/tests/experimental-parse-class-name.test.ts new file mode 100644 index 0000000..889b0c4 --- /dev/null +++ b/tests/experimental-parse-class-name.test.ts @@ -0,0 +1,37 @@ +import { extendTailwindMerge } from '../src' + +test('default case', () => { + const twMerge = extendTailwindMerge({ + experimentalParseClassName({ className, parseClassName }) { + return parseClassName(className) + }, + }) + + expect(twMerge('px-2 py-1 p-3')).toBe('p-3') +}) + +test('removing first three characters from class', () => { + const twMerge = extendTailwindMerge({ + experimentalParseClassName({ className, parseClassName }) { + return parseClassName(className.slice(3)) + }, + }) + + expect(twMerge('barpx-2 foopy-1 lolp-3')).toBe('lolp-3') +}) + +test('ignoring breakpoint modifiers', () => { + const breakpoints = new Set(['sm', 'md', 'lg', 'xl', '2xl']) + const twMerge = extendTailwindMerge({ + experimentalParseClassName({ className, parseClassName }) { + const parsed = parseClassName(className) + + return { + ...parsed, + modifiers: parsed.modifiers.filter((modifier) => !breakpoints.has(modifier)), + } + }, + }) + + expect(twMerge('md:px-2 hover:py-4 py-1 lg:p-3')).toBe('hover:py-4 lg:p-3') +})