mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-02 16:04:04 +03:00
09ff9af9a2
* attrsToString: To avoid some malformed attributes
Error:
```
TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at attrsToString
```
This errors appears if no `attrs` setted in custom tag:
```
const BBcodePresetTemp = BbobPresetHTML5.extend((tags: any) => {
tags.br = () => ({
tag: 'br',
// attrs: {}, // <-- Comment this line for error and add [br] to text
content: null,
});
return tags;
});
```
87 lines
1.6 KiB
JavaScript
87 lines
1.6 KiB
JavaScript
import {
|
|
attrsToString,
|
|
attrValue,
|
|
appendToNode,
|
|
getNodeLength,
|
|
isTagNode,
|
|
isStringNode,
|
|
isEOL,
|
|
} from '../src';
|
|
|
|
describe('@bbob/plugin-helper', () => {
|
|
test('appendToNode', () => {
|
|
const value = 'test';
|
|
const node = { content: [] };
|
|
|
|
appendToNode(node, value);
|
|
expect(node.content.pop()).toBe(value);
|
|
});
|
|
|
|
test('getNodeLength', () => {
|
|
const node = {
|
|
tag: 'test',
|
|
content: [
|
|
'123',
|
|
{
|
|
tag: 'test2',
|
|
content: ['123']
|
|
}
|
|
]
|
|
};
|
|
|
|
expect(getNodeLength(node)).toBe(6)
|
|
});
|
|
|
|
test('isTagNode', () => {
|
|
const node = {
|
|
tag: 'test',
|
|
content: []
|
|
};
|
|
|
|
expect(isTagNode(node)).toBe(true)
|
|
});
|
|
|
|
test('isStringNode', () => {
|
|
const node = {
|
|
tag: 'test',
|
|
content: ['123']
|
|
};
|
|
|
|
expect(isStringNode(node.content[0])).toBe(true);
|
|
});
|
|
|
|
test('attrValue boolean', () => {
|
|
expect(attrValue('test', true)).toBe('test');
|
|
});
|
|
|
|
test('attrValue number', () => {
|
|
expect(attrValue('test', 123)).toBe('test="123"');
|
|
});
|
|
|
|
test('attrValue string', () => {
|
|
expect(attrValue('test', 'hello')).toBe('test="hello"');
|
|
});
|
|
|
|
test('attrValue object', () => {
|
|
const attrs = { tag: 'test' };
|
|
|
|
expect(attrValue('test', attrs)).toBe('test="{"tag":"test"}"');
|
|
});
|
|
|
|
test('isEOL', () => {
|
|
expect(isEOL('\n')).toBe(true)
|
|
});
|
|
|
|
test('attrsToString', () => {
|
|
expect(attrsToString({
|
|
tag: 'test',
|
|
foo: 'bar',
|
|
disabled: true
|
|
})).toBe(` tag="test" foo="bar" disabled`)
|
|
})
|
|
|
|
test('attrsToString undefined', () => {
|
|
expect(attrsToString(undefined)).toBe('')
|
|
})
|
|
});
|