diff --git a/packages/clients/src/helpers/__tests__/is-browser.browser.ts b/packages/clients/src/helpers/__tests__/is-browser.browser.ts new file mode 100644 index 000000000..36af77921 --- /dev/null +++ b/packages/clients/src/helpers/__tests__/is-browser.browser.ts @@ -0,0 +1,9 @@ +/* @jest-environment jsdom */ +import { describe, expect, it } from '@jest/globals' +import { isBrowser } from '../is-browser' + +describe('isBrowser', () => { + it('returns true by default', () => { + expect(isBrowser()).toBe(true) + }) +}) diff --git a/packages/clients/src/helpers/__tests__/is-browser.node.ts b/packages/clients/src/helpers/__tests__/is-browser.node.ts new file mode 100644 index 000000000..1602bd363 --- /dev/null +++ b/packages/clients/src/helpers/__tests__/is-browser.node.ts @@ -0,0 +1,9 @@ +/* @jest-environment node */ +import { describe, expect, it } from '@jest/globals' +import { isBrowser } from '../is-browser' + +describe('isBrowser', () => { + it('returns false by default', () => { + expect(isBrowser()).toBe(false) + }) +}) diff --git a/packages/clients/src/helpers/__tests__/is-browser.ts b/packages/clients/src/helpers/__tests__/is-browser.ts deleted file mode 100644 index 734197d3a..000000000 --- a/packages/clients/src/helpers/__tests__/is-browser.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { describe, expect, it } from '@jest/globals' -import { isBrowser } from '../is-browser' - -describe('isBrowser', () => { - it('returns false by default', () => { - expect(isBrowser()).toBe(!!global.window) - }) - - it('returns true after defining a window', () => { - // @ts-expect-error Fake window/document for the test - global.window = { document: 'not-undefined' } - expect(isBrowser()).toBe(true) - // @ts-expect-error Reset the global variable - delete global.window - }) -}) diff --git a/packages/clients/src/scw/fetch/__tests__/build-fetcher.ts b/packages/clients/src/scw/fetch/__tests__/build-fetcher.ts index d72ad8bf3..f7fc53ee9 100644 --- a/packages/clients/src/scw/fetch/__tests__/build-fetcher.ts +++ b/packages/clients/src/scw/fetch/__tests__/build-fetcher.ts @@ -43,17 +43,6 @@ describe(`buildRequest`, () => { }) } - it(`has NOT the header "User-Agent" when browser is detected`, () => { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-expect-error Fake window/document for the test - global.window = { document: 'not-undefined' } - const fReq = buildRequest(SCW_POST_REQUEST, DEFAULT_SETTINGS) - expect(fReq.headers.get('User-Agent')).toBeNull() - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-expect-error Reset the global variable - delete global.window - }) - it(`has the custom headers`, () => { const mReq: ScwRequest = { ...SCW_POST_REQUEST, diff --git a/packages/clients/src/scw/fetch/build-fetcher.ts b/packages/clients/src/scw/fetch/build-fetcher.ts index 871b10252..6fe1d0d65 100644 --- a/packages/clients/src/scw/fetch/build-fetcher.ts +++ b/packages/clients/src/scw/fetch/build-fetcher.ts @@ -32,7 +32,9 @@ export const buildRequest = ( body: request.body, headers: { Accept: 'application/json', - ...(!isBrowser() ? { 'User-Agent': settings.userAgent } : {}), + .../* istanbul ignore next */ (!isBrowser() + ? { 'User-Agent': settings.userAgent } + : {}), ...request.headers, }, method: request.method,