tailwindcss/tests/prefixSelector.test.js
Robin Malfait d497777202 [WIP] Unify JIT and AOT code paths (#4188)
* WIP

* WIP

* Finish combining JIT and AOT plugins

Still lots of clean up that can be done in some of the more complex ones, but at least it's one file per plugin now.

* Remove unused import

* Fix AOT generation bugs

* Move corePlugins/index.js to corePlugins.js

* Convert JIT files to ESM

* Move tests

* Reorder core plugins to match JIT order

* Update AOT apply tests

* Unify utils

* Combine plugin lists to one single source of truth

* Finish resolving merge conflicts, fix tests

Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2021-05-07 13:56:15 -04:00

27 lines
890 B
JavaScript

import prefix from '../src/util/prefixSelector'
test('it prefixes classes with the provided prefix', () => {
expect(prefix('tw-', '.foo')).toEqual('.tw-foo')
})
test('it handles a function as the prefix', () => {
const prefixFunc = (selector) => {
return selector === '.foo' ? 'tw-' : ''
}
expect(prefix(prefixFunc, '.foo')).toEqual('.tw-foo')
expect(prefix(prefixFunc, '.bar')).toEqual('.bar')
})
test('it properly prefixes selectors with non-standard characters', () => {
expect(prefix('tw-', '.hello\\:world')).toEqual('.tw-hello\\:world')
expect(prefix('tw-', '.foo\\/bar')).toEqual('.tw-foo\\/bar')
expect(prefix('tw-', '.wew\\.lad')).toEqual('.tw-wew\\.lad')
})
test('it prefixes all classes in a selector', () => {
expect(prefix('tw-', '.btn-blue .w-1\\/4 > h1.text-xl + a .bar')).toEqual(
'.tw-btn-blue .tw-w-1\\/4 > h1.tw-text-xl + a .tw-bar'
)
})