Skip to main content
Module

x/urlcat/test/join.ts

A URL builder library for JavaScript.
Go to Latest
File
import { join } from '../src';import { expect } from 'chai';
describe('join', () => {
it('Returns empty string if all arguments are empty', () => { const expected = ''; const actual = join('', '', ''); expect(actual).to.equal(expected); });
it('Returns empty string if the separator is specified but the two parts are empty', () => { const expected = ''; const actual = join('', '&', ''); expect(actual).to.equal(expected); });
it('Removes the separator at the beginning of the second part if the first part is empty', () => { const expected = 'second-part'; const actual = join('', '&', '&second-part'); expect(actual).to.equal(expected); });
it('Removes the separator at the end of the first part if the second part is empty', () => { const expected = 'first-part'; const actual = join('first-part&', '&', ''); expect(actual).to.equal(expected); });
it('If neither part contains the separator at the boundary, it joins them using it', () => { const expected = 'first,second'; const actual = join('first', ',', 'second'); expect(actual).to.equal(expected); });
it('Ignores the separator if it is not at the boundary', () => { const expected = 'a|b|c||de|f'; const actual = join('a|b', '|', '|c||de|f'); expect(actual).to.equal(expected); });
it('Uses exactly one separator even if the first part ends with it', () => { const expected = 'first,second'; const actual = join('first,', ',', 'second'); expect(actual).to.equal(expected); });
it('Uses exactly one separator even if the second part starts with it', () => { const expected = 'first,second'; const actual = join('first', ',', ',second'); expect(actual).to.equal(expected); });
it('Uses exactly one separator even if the first part ends with it and the second part starts with it', () => { const expected = 'first,second'; const actual = join('first,', ',', ',second'); expect(actual).to.equal(expected); });
it('Uses the separator if it is not present at the boundary', () => { const expected = 'first,second'; const actual = join('first', ',', 'second'); expect(actual).to.equal(expected); });
});