Skip to content

Commit 1fb324a

Browse files
authored
test: adjust window coverage (#471)
1 parent c0deb0a commit 1fb324a

File tree

5 files changed

+21
-28
lines changed

5 files changed

+21
-28
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* @jest-environment jsdom */
2+
import { describe, expect, it } from '@jest/globals'
3+
import { isBrowser } from '../is-browser'
4+
5+
describe('isBrowser', () => {
6+
it('returns true by default', () => {
7+
expect(isBrowser()).toBe(true)
8+
})
9+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* @jest-environment node */
2+
import { describe, expect, it } from '@jest/globals'
3+
import { isBrowser } from '../is-browser'
4+
5+
describe('isBrowser', () => {
6+
it('returns false by default', () => {
7+
expect(isBrowser()).toBe(false)
8+
})
9+
})

packages/clients/src/helpers/__tests__/is-browser.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/clients/src/scw/fetch/__tests__/build-fetcher.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,6 @@ describe(`buildRequest`, () => {
4343
})
4444
}
4545

46-
it(`has NOT the header "User-Agent" when browser is detected`, () => {
47-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
48-
// @ts-expect-error Fake window/document for the test
49-
global.window = { document: 'not-undefined' }
50-
const fReq = buildRequest(SCW_POST_REQUEST, DEFAULT_SETTINGS)
51-
expect(fReq.headers.get('User-Agent')).toBeNull()
52-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
53-
// @ts-expect-error Reset the global variable
54-
delete global.window
55-
})
56-
5746
it(`has the custom headers`, () => {
5847
const mReq: ScwRequest = {
5948
...SCW_POST_REQUEST,

packages/clients/src/scw/fetch/build-fetcher.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export const buildRequest = (
3232
body: request.body,
3333
headers: {
3434
Accept: 'application/json',
35-
...(!isBrowser() ? { 'User-Agent': settings.userAgent } : {}),
35+
.../* istanbul ignore next */ (!isBrowser()
36+
? { 'User-Agent': settings.userAgent }
37+
: {}),
3638
...request.headers,
3739
},
3840
method: request.method,

0 commit comments

Comments
 (0)