@apistudio/apim-cli
Version:
CLI for API Management Products
30 lines (24 loc) • 1.15 kB
text/typescript
/**
* Copyright Super iPaaS Integration LLC, an IBM Company 2024
*/
import { cropPrefix} from './string-helper.js';
describe('String helper test suite', () => {
describe('cropPrefix function:', () => {
it('should return input if input is null or undefined', () => {
expect(cropPrefix(null as unknown as string, 'prefix')).toBe(null);
expect(cropPrefix(undefined as unknown as string, 'prefix')).toBe(undefined);
});
it('should return input if prefix is null or undefined', () => {
expect(cropPrefix('someString', null as unknown as string)).toBe('someString');
expect(cropPrefix('someString', undefined as unknown as string)).toBe('someString');
});
it('should remove the prefix if it is present at the start of the input', () => {
expect(cropPrefix('prefixSomething', 'prefix')).toBe('Something');
expect(cropPrefix('prefixSomething', 'pre')).toBe('fixSomething');
});
it('should return the input unchanged if the prefix does not match', () => {
expect(cropPrefix('someString', 'prefix')).toBe('someString');
expect(cropPrefix('prefixSomething', 'nonexistent')).toBe('prefixSomething');
});
});
});