Skip to content

Commit 982f649

Browse files
committed
test(utils): unit tests for withPrefix utility
1 parent d31480b commit 982f649

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/utils/__tests__/get-class-list-from-props.test.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77

88
import { FontAwesomeIconProps } from '../../types/icon-props'
99
import { IS_VERSION_7_OR_LATER } from '../constants'
10-
import { getClassListFromProps } from '../get-class-list-from-props'
10+
import { getClassListFromProps, withPrefix } from '../get-class-list-from-props'
1111

1212
describe('get class list', () => {
1313
const props = {
@@ -168,3 +168,29 @@ describe('get class list', () => {
168168
})
169169
})
170170
})
171+
172+
describe('withPrefix utility function', () => {
173+
const customPrefix = 'custom-prefix'
174+
175+
beforeEach(() => {
176+
config.cssPrefix = customPrefix
177+
})
178+
179+
it('should prefix a single class', () => {
180+
expect(withPrefix('fa-icon')).toBe('custom-prefix-icon')
181+
})
182+
183+
it('should prefix multiple space-separated classes', () => {
184+
expect(withPrefix('fa-icon fa-spin fa-lg')).toBe(
185+
'custom-prefix-icon custom-prefix-spin custom-prefix-lg',
186+
)
187+
})
188+
189+
it('should return empty string when given empty string', () => {
190+
expect(withPrefix('')).toBe('')
191+
})
192+
193+
it('should do nothing and return same string when given only whitespace', () => {
194+
expect(withPrefix(' ')).toBe(' ')
195+
})
196+
})

0 commit comments

Comments
 (0)