diff --git a/src/primitives.test.ts b/src/primitives.test.ts index 3693c8a..ef378a4 100644 --- a/src/primitives.test.ts +++ b/src/primitives.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/ban-ts-comment */ import type * as Subject from './primitives' import * as subject from './primitives' @@ -30,6 +31,10 @@ namespace TypeTests { type test10 = Expect, 16>> } +beforeEach(() => { + vi.clearAllMocks() +}) + describe('primitives', () => { describe('charAt', () => { test('should get the character of a string at the given index in both type and runtime level', () => { @@ -89,6 +94,25 @@ describe('primitives', () => { }) }) + describe('replaceAll polyfill', () => { + const replaceAll = String.prototype.replaceAll + beforeAll(() => { + // @ts-ignore + String.prototype.replaceAll = undefined + }) + + afterAll(() => { + String.prototype.replaceAll = replaceAll + }) + test('it works through a polifyll', () => { + const spy = vi.spyOn(String.prototype, 'replace') + const data = 'some nice string' + const result = subject.replaceAll(data, ' ', '@') + expect(result).toEqual('some@nice@string') + expect(spy).toHaveBeenCalledWith(/ /g, '@') + }) + }) + describe('slice', () => { const str = 'The quick brown fox jumps over the lazy dog.' test('should slice a string from a startIndex position', () => {