Skip to content

Commit

Permalink
add tests for experimentalParseClassName
Browse files Browse the repository at this point in the history
  • Loading branch information
dcastil committed Jul 7, 2024
1 parent 6812bf7 commit 9aa1c8e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/experimental-parse-class-name.test.ts
Original file line number Diff line number Diff line change
@@ -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')
})

0 comments on commit 9aa1c8e

Please sign in to comment.