Files
cloudbeaver/webapp/packages/core-utils/src/replaceSubstring.test.ts
T
sergeyteleshevandAleksei Potsetsuev 74486b35b4 CB-5340 adds unit tests for basic hooks (#2755)
* CB-5340 adds unit tests for basic hooks

* CB-5340 test: trigger github actions

* CB-5340 fixes unit tests

* CB-5340 fixes unit tests

* CB-5340 fixes unit tests

* CB-5340 adds jest moduled imports for unit tests

* CB-5340 adds jest moduled imports for unit tests

* CB-5340 revert some changes

* CB-5340 cleanup

* CB-5340 replaces global jest to moduled

* CB-5340 uncomment tests and skip it

* CB-5340 cleanup

* chore: enable jest globals

* CB-5340 fix unit tests

---------

Co-authored-by: Aleksei Potsetsuev <wrouds@gmail.com>
2024-08-07 12:42:43 +03:00

38 lines
1.2 KiB
TypeScript

/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { describe, expect, it } from '@jest/globals';
import { replaceSubstring } from './replaceSubstring';
describe('replaceSubstring', () => {
it('should replace a substring correctly', () => {
const result = replaceSubstring('Hello, world!', 7, 12, 'there');
expect(result).toBe('Hello, there!');
});
it('should handle beginIndex at the start', () => {
const result = replaceSubstring('Hello, world!', 0, 5, 'Hi');
expect(result).toBe('Hi, world!');
});
it('should handle endIndex at the end', () => {
const result = replaceSubstring('Hello, world!', 7, 13, 'everyone');
expect(result).toBe('Hello, everyone');
});
it('should handle empty replacement', () => {
const result = replaceSubstring('Hello, world!', 7, 13, '');
expect(result).toBe('Hello, ');
});
it('should handle replacement longer than the substring', () => {
const result = replaceSubstring('Hello, world!', 7, 12, 'everyone out there');
expect(result).toBe('Hello, everyone out there!');
});
});