Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/string/trimStart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ describe('trimStart', () => {
expect(trimStart(' hello world ')).toEqual('hello world ');
});

it('should throw an error when chars is a multi-character string', () => {
expect(() => trimStart('---hello', '--')).toThrow();
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test should verify the exact error message for consistency with the trimEnd tests. The trimEnd.spec.ts file (line 66) tests the exact error message with: expect(() => trimEnd('hello', 'ab')).toThrow(\The 'chars' parameter should be a single character string.`);` This test should follow the same pattern.

Copilot uses AI. Check for mistakes.
});
Comment on lines +49 to +51
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a test case for an empty string as the chars parameter (e.g., trimStart('hello', '')). This would also trigger the validation error since an empty string has length 0, not 1. While trimEnd.spec.ts also lacks this test case, adding it here would improve edge case coverage.

Copilot uses AI. Check for mistakes.

it('should remove leading characters when chars is an array', () => {
expect(trimStart('---hello', ['-', 'h'])).toEqual('ello');
});
Expand Down
4 changes: 4 additions & 0 deletions src/string/trimStart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export function trimStart(str: string, chars?: string | string[]): string {

switch (typeof chars) {
case 'string': {
if (chars.length !== 1) {
throw new Error(`The 'chars' parameter should be a single character string.`);
}

while (startIndex < str.length && str[startIndex] === chars) {
startIndex++;
}
Expand Down
Loading