Skip to content

Commit

Permalink
test: Add a test for the polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavoguichard committed Oct 4, 2023
1 parent 00a7831 commit ecf79bc
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/primitives.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import type * as Subject from './primitives'
import * as subject from './primitives'

Expand Down Expand Up @@ -30,6 +31,10 @@ namespace TypeTests {
type test10 = Expect<Equal<Subject.Length<'some nice string'>, 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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit ecf79bc

Please sign in to comment.