2022-09-19 12:00:09 -04:00
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
2023-01-05 10:54:06 -05:00
import { it , describe , expect } from "vitest" ;
2023-10-11 11:30:41 -04:00
import { getUniqueName , postfix } from "../utils/util-string" ;
2022-09-19 12:00:09 -04:00
describe ( "util-string" , ( ) => {
describe ( "getUniqueName" , ( ) => {
it ( "should return a string" , ( ) => {
const name = getUniqueName ( "Hello" ) ;
expect ( typeof name ) . toBe ( "string" ) ;
} ) ;
it ( "should return a unique name even when passed the same value" , ( ) => {
const value = "Hello" ;
const u1 = getUniqueName ( value ) ;
const u2 = getUniqueName ( value ) ;
expect ( u1 ) . not . toEqual ( u2 ) ;
} ) ;
2024-10-02 11:09:03 -04:00
2024-10-03 09:54:34 -04:00
it ( "should throw an error if a falsy value is passed in for the prefix" , ( ) => {
expect ( ( ) => getUniqueName ( ) ) . toThrowError ( ) ;
expect ( ( ) => getUniqueName ( "" ) ) . toThrowError ( ) ;
expect ( ( ) => getUniqueName ( 0 ) ) . toThrowError ( ) ;
2024-10-02 11:09:03 -04:00
} ) ;
2022-09-19 12:00:09 -04:00
} ) ;
describe ( "postfix" , ( ) => {
2023-01-24 17:06:06 -05:00
it ( "should add the provided string to the end of the source string" , ( ) => {
expect ( postfix ( "Hello " , "World" ) ) . toEqual ( "Hello World" ) ;
} ) ;
2022-09-19 12:00:09 -04:00
2023-01-24 17:06:06 -05:00
it ( "should throw an error when given a non-string as the value to affix" , ( ) => {
expect ( ( ) => postfix ( "Hello " , 123 ) ) . toThrow ( ) ;
} ) ;
2022-09-19 12:00:09 -04:00
} ) ;
} ) ;