Skip to content

Instantly share code, notes, and snippets.

@maatthc
Created August 30, 2021 04:05

Revisions

  1. maatthc created this gist Aug 30, 2021.
    22 changes: 22 additions & 0 deletions url.test.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    import urlBuilder from './url'

    let location: Location

    describe('urlBuilder', () => {
    beforeEach(() => {
    location = window.location
    jest.spyOn(window, 'location', 'get').mockRestore()
    })

    test('given path, should return valid url', () => {
    const mockedLocation = {
    ...location,
    protocol: 'https:',
    host: 'www.google.com.au'
    }
    jest.spyOn(window, 'location', 'get').mockReturnValue(mockedLocation)
    const expectedUrl = 'https://www.google.com.br/faq'
    const result = urlBuilder('/static/faq')
    expect(result).toBe(expectedUrl)
    })
    })