51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { callableObject, escapeHTML, identity } from '@/internal/utils'
|
|
|
|
|
|
describe('.callableObject', () => {
|
|
|
|
describe('returned value', () => {
|
|
const template = {
|
|
str: 'allons-y!',
|
|
func1: jest.fn().mockReturnValue(1),
|
|
func2: jest.fn().mockReturnValue(2),
|
|
}
|
|
const subject = callableObject('func1', template)
|
|
|
|
it('is a function that calls the specified template function', () => {
|
|
expect( subject ).toBeInstanceOf(Function)
|
|
expect( subject('a', 'b') ).toBe(1)
|
|
expect( template.func1 ).toBeCalledWith('a', 'b')
|
|
})
|
|
|
|
it('is not the same function as the specified template function', () => {
|
|
expect( subject ).not.toBe(template.func1)
|
|
})
|
|
|
|
it('has all enumerable properties of the given template', () => {
|
|
expect( subject )
|
|
.toHaveProperty('str', template.str)
|
|
.toHaveProperty('func1', template.func1)
|
|
.toHaveProperty('func2', template.func2)
|
|
})
|
|
})
|
|
})
|
|
|
|
|
|
describe('.escapeHTML', () => {
|
|
test.each([
|
|
/* input | expected */
|
|
['&' , '&' ],
|
|
['<' , '<' ],
|
|
['>' , '>' ],
|
|
['Hey >_<! <<&>>', 'Hey >_<! <<&>>'],
|
|
])('"%s" -> "%s"', (input, expected) => {
|
|
expect( escapeHTML(input) ).toEqual(expected)
|
|
})
|
|
})
|
|
|
|
|
|
describe('.identity', () => {
|
|
it('returns the first given argument', () => {
|
|
expect( identity('a', 'b') ).toBe('a')
|
|
})
|
|
})
|