/* eslint-disable no-irregular-whitespace */ import {objectIsEmpty, isObject, longestWord, getRandomItem} from '../helpers' import {vi} from 'vitest' describe(`objectIsEmpty`, () => { it(`works`, () => { expect(objectIsEmpty({})).toBe(true) expect(objectIsEmpty({some: {thing: {}}})).toBe(false) expect(objectIsEmpty(undefined)).toBe(false) expect(objectIsEmpty(``)).toBe(false) expect(objectIsEmpty([])).toBe(true) }) }) describe(`isObject`, () => { it(`works`, () => { expect(isObject({})).toBe(true) expect(isObject({some: {thing: {}}})).toBe(true) expect(isObject(undefined)).toBe(false) expect(isObject(``)).toBe(false) expect(isObject([])).toBe(false) }) }) describe(`longestWord`, () => { it(`works`, () => { expect(longestWord(`hello worlds`)).toBe(`worlds`) expect(longestWord(`worlds hello `)).toBe(`worlds`) // spaces and returns should be word separators expect(longestWord(`\t \nworlds\n \r\nhello `)).toBe(`worlds`) // hyphens, full stops and other punctuation are included as part of a word expect(longestWord(`“worlds-hello”.`)).toBe(`“worlds-hello”.`) // forward slash can be used as a word separator expect(longestWord(`worlds/hello`)).toBe(`worlds`) // non-breaking spaces should be included in longestWord expect(longestWord(`worlds hello`)).toBe(`worlds hello`) // non-breaking spaces should be included in longestWord expect(longestWord(`REAL. RUGGED. READY FOR ANYTHING`)).toBe(`REAL. RUGGED. READY`) }) }) describe(`getRandomItem`, () => { it(`returns a random item of a supplied array or string`, () => { expect(getRandomItem()).toBeUndefined() expect(getRandomItem([1])).toBe(1) vi.spyOn(Math, `random`).mockReturnValueOnce(0.49) expect(getRandomItem([1, 2])).toEqual(1) vi.spyOn(Math, `random`).mockReturnValueOnce(0.5) expect(getRandomItem([1, 2])).toEqual(2) vi.spyOn(Math, `random`).mockReturnValueOnce(0.5) expect(getRandomItem([1, 2, 3])).toEqual(2) vi.spyOn(Math, `random`).mockReturnValueOnce(0.67) expect(getRandomItem([1, 2, 3])).toEqual(3) }) })