test(aio): add tests for renderAttributes helper
This commit is contained in:

committed by
Pete Bacon Darwin

parent
c757e5794f
commit
2eca6e67e1
@ -1,4 +1,4 @@
|
||||
const { mapObject, parseAttributes } = require('./utils');
|
||||
const { mapObject, parseAttributes, renderAttributes } = require('./utils');
|
||||
|
||||
describe('utils', () => {
|
||||
describe('mapObject', () => {
|
||||
@ -73,4 +73,27 @@ describe('utils', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('renderAttributes', () => {
|
||||
it('should convert key-value map to a strong that can be used in HTML', () => {
|
||||
expect(renderAttributes({ foo: 'bar', moo: 'car' })).toEqual(' foo="bar" moo="car"');
|
||||
});
|
||||
|
||||
it('should handle boolean values', () => {
|
||||
expect(renderAttributes({ foo: 'bar', loo: true, moo: false }))
|
||||
.toEqual(' foo="bar" loo');
|
||||
});
|
||||
|
||||
it('should escape double quotes inside the value', () => {
|
||||
expect(renderAttributes({ foo: 'bar "car"' })).toEqual(' foo="bar "car""');
|
||||
});
|
||||
|
||||
it('should not escape single quotes inside the value', () => {
|
||||
expect(renderAttributes({ foo: 'bar \'car\'' })).toEqual(' foo="bar \'car\'"');
|
||||
});
|
||||
|
||||
it('should handle an empty object', () => {
|
||||
expect(renderAttributes({ })).toEqual('');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user