add tests

This commit is contained in:
Jesper Møller Jensen
2023-12-08 13:18:43 +13:00
committed by Jacob Overgaard
parent b6dd4d016c
commit 2d37411f5f

View 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([]);
});
});