From 218cb435faba6bbb20da73a4149a8df2679af11f Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 2 Oct 2024 20:32:41 +0200 Subject: [PATCH] Create string-or-string-array-contains.function.test.ts --- ...-or-string-array-contains.function.test.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/Umbraco.Web.UI.Client/src/packages/core/utils/string/string-or-string-array-contains/string-or-string-array-contains.function.test.ts diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/utils/string/string-or-string-array-contains/string-or-string-array-contains.function.test.ts b/src/Umbraco.Web.UI.Client/src/packages/core/utils/string/string-or-string-array-contains/string-or-string-array-contains.function.test.ts new file mode 100644 index 0000000000..3f2051e663 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/core/utils/string/string-or-string-array-contains/string-or-string-array-contains.function.test.ts @@ -0,0 +1,34 @@ +import { stringOrStringArrayContains } from './string-or-string-array-contains.function.js'; +import { expect } from '@open-wc/testing'; + +describe('stringOrStringArrayContains', () => { + it('returns true if a string matches a search string', () => { + const result = stringOrStringArrayContains('hello', 'hello'); + expect(result).to.be.true; + }); + + it('returns false if a string does not contain a search string', () => { + const result = stringOrStringArrayContains('hello', 'world'); + expect(result).to.be.false; + }); + + it('returns false if a search string partly matches the string', () => { + const result = stringOrStringArrayContains('hello', 'ello'); + expect(result).to.be.false; + }); + + it('returns true if an array of strings contains a search string', () => { + const result = stringOrStringArrayContains(['hello', 'world'], 'world'); + expect(result).to.be.true; + }); + + it('returns false if an array of strings does not contain a search string', () => { + const result = stringOrStringArrayContains(['hello', 'world'], 'foo'); + expect(result).to.be.false; + }); + + it('returns false if an empty array is passed', () => { + const result = stringOrStringArrayContains([], 'foo'); + expect(result).to.be.false; + }); +});