UNPKG

string-tool

Version:

Useful functions for Strings

35 lines (34 loc) 1.64 kB
"use strict"; exports.__esModule = true; var String_1 = require("../String"); describe('startsWith', function () { it('should return true when the string starts with another string', function () { expect(String_1.startsWith('A test', 'A t')).toBe(true); expect(String_1.startsWith('A test', 'A test')).toBe(true); }); it('should return false when the string starts with something else', function () { expect(String_1.startsWith('something', 'nothing')).toBe(false); }); }); describe('capitalize', function () { it('should return true when the first letter was capitalized correctly', function () { expect(String_1.capitalize('a')).toEqual('A'); expect(String_1.capitalize('ß')).toEqual('SS'); expect(String_1.capitalize('über')).toEqual('Über'); expect(String_1.capitalize('égalité')).toEqual('Égalité'); }); it('should return an empty string when the input is empty', function () { expect(String_1.capitalize('')).toEqual(''); }); }); describe('nthIndexOf', function () { it('should find the position of the searchString', function () { expect(String_1.nthIndexOf('testtest test', 1, 'test')).toEqual(0); expect(String_1.nthIndexOf('testtest test', 2, 'test')).toEqual(4); expect(String_1.nthIndexOf('testtest test', 3, 'test')).toEqual(9); }); it('should return undefined when the searchString does not exist', function () { expect(String_1.nthIndexOf('testtest test', 0, 'test')).toBe(undefined); expect(String_1.nthIndexOf('bla bla bla', 2, 'test')).toBe(undefined); }); });