Skip to content

Commit e97814b

Browse files
committed
Add tests
1 parent ea3c5a3 commit e97814b

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

packages/tailwindcss-language-service/src/util/find.test.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { test } from 'vitest'
22
import { findClassListsInHtmlRange } from './find'
3-
import { js, html, createDocument } from './test-utils'
3+
import { js, html, pug, createDocument } from './test-utils'
44

55
test('class regex works in astro', async ({ expect }) => {
66
let file = createDocument({
@@ -735,3 +735,59 @@ test('classAttributes find class lists inside variables in JS(X)/TS(X)', async (
735735
},
736736
])
737737
})
738+
739+
test('classAttributes find class lists inside pug', async ({ expect }) => {
740+
let file = createDocument({
741+
name: 'file.pug',
742+
lang: 'pug',
743+
settings: {
744+
tailwindCSS: {
745+
classAttributes: ['className'],
746+
},
747+
},
748+
content: pug`
749+
div(classNAme="relative flex")
750+
`,
751+
})
752+
753+
let classLists = await findClassListsInHtmlRange(file.state, file.doc, 'js')
754+
755+
expect(classLists).toEqual([
756+
{
757+
classList: 'relative flex',
758+
range: {
759+
start: { line: 0, character: 15 },
760+
end: { line: 0, character: 28 },
761+
},
762+
},
763+
])
764+
})
765+
766+
test('classAttributes find class lists inside Vue bindings', async ({ expect }) => {
767+
let file = createDocument({
768+
name: 'file.pug',
769+
lang: 'vue',
770+
settings: {
771+
tailwindCSS: {
772+
classAttributes: ['class'],
773+
},
774+
},
775+
content: html`
776+
<template>
777+
<div :class="{'relative flex': true}"></div>
778+
</template>
779+
`,
780+
})
781+
782+
let classLists = await findClassListsInHtmlRange(file.state, file.doc, 'js')
783+
784+
expect(classLists).toEqual([
785+
{
786+
classList: 'relative flex',
787+
range: {
788+
start: { line: 1, character: 17 },
789+
end: { line: 1, character: 30 },
790+
},
791+
},
792+
])
793+
})

packages/tailwindcss-language-service/src/util/test-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const ts = dedent
99
export const tsx = dedent
1010
export const css = dedent
1111
export const html = dedent
12+
export const pug = dedent
1213

1314
export function createDocument({
1415
name,

0 commit comments

Comments
 (0)