add tests
This commit is contained in:
committed by
Jacob Overgaard
parent
b6dd4d016c
commit
2d37411f5f
39
src/Umbraco.Web.UI.Client/src/shared/utils/utils.test.ts
Normal file
39
src/Umbraco.Web.UI.Client/src/shared/utils/utils.test.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { expect } from '@open-wc/testing';
|
||||
import { splitStringToArray } from './split-string-to-array.js';
|
||||
|
||||
describe('splitStringToArray', () => {
|
||||
it('splits and cleans a comma-separated string', () => {
|
||||
const inputString = 'one, two, three, ,five';
|
||||
const result = splitStringToArray(inputString);
|
||||
|
||||
expect(result).to.deep.equal(['one', 'two', 'three', 'five']);
|
||||
});
|
||||
|
||||
it('handles custom delimiters', () => {
|
||||
const inputString = 'apple | orange | banana';
|
||||
const result = splitStringToArray(inputString, ' | ');
|
||||
|
||||
expect(result).to.deep.equal(['apple', 'orange', 'banana']);
|
||||
});
|
||||
|
||||
it('handles strings with no non-empty elements', () => {
|
||||
const inputString = ', , , , ';
|
||||
const result = splitStringToArray(inputString);
|
||||
|
||||
expect(result).to.deep.equal([]);
|
||||
});
|
||||
|
||||
it('trims whitespace from each element', () => {
|
||||
const inputString = ' one , two , three ';
|
||||
const result = splitStringToArray(inputString);
|
||||
|
||||
expect(result).to.deep.equal(['one', 'two', 'three']);
|
||||
});
|
||||
|
||||
it('returns an empty array for an empty string', () => {
|
||||
const inputString = '';
|
||||
const result = splitStringToArray(inputString);
|
||||
|
||||
expect(result).to.deep.equal([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user