Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"root": true,
"env": {
"browser": true,
"jest": true
"browser": true
},
"overrides": [
{
Expand Down Expand Up @@ -30,6 +29,15 @@
"rules": {
"no-console": "off"
}
},
{
"files": [
"packages/jest-helpers/**/*.ts{x,}",
"**/__tests__/**/*.ts{x,}"
],
"rules": {
"import/no-extraneous-dependencies": "off"
}
}
]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
"@changesets/cli": "2.26.2",
"@commitlint/cli": "17.7.1",
"@commitlint/config-conventional": "17.7.0",
"@jest/globals": "^29.6.4",
"@rollup/plugin-babel": "6.0.3",
"@rollup/plugin-node-resolve": "15.2.1",
"@scaleway/eslint-config-react": "workspace:*",
"@scaleway/tsconfig": "workspace:*",
"@testing-library/jest-dom": "5.17.0",
"@testing-library/jest-dom": "6.0.1",
"@testing-library/react": "13.4.0",
"@tsd/typescript": "5.1.6",
"@types/jest": "29.5.4",
"@types/node": "18.17.9",
"@types/prop-types": "15.7.5",
"@types/react": "18.2.21",
Expand Down
13 changes: 7 additions & 6 deletions packages/changesets-renovate/src/__tests__/generate-changeset.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals'
import fs from 'node:fs/promises'
import { simpleGit } from 'simple-git'
import { run } from '..'
Expand Down Expand Up @@ -95,9 +96,9 @@ describe('generate changeset file', () => {
})

fs.readFile = jest
.fn()
.fn<any>()
.mockResolvedValue(`{"name":"packageName","version":"1.0.0"}`)
fs.writeFile = jest.fn()
fs.writeFile = jest.fn<any>()

await run()

Expand Down Expand Up @@ -129,9 +130,9 @@ describe('generate changeset file', () => {
})

fs.readFile = jest
.fn()
.fn<any>()
.mockResolvedValue(`{"name":"packageName","workspaces":[]}`)
fs.writeFile = jest.fn()
fs.writeFile = jest.fn<any>()

await run()

Expand Down Expand Up @@ -159,8 +160,8 @@ describe('generate changeset file', () => {
`,
})

fs.readFile = jest.fn().mockResolvedValue(`{"name":"packageName"}`)
fs.writeFile = jest.fn()
fs.readFile = jest.fn<any>().mockResolvedValue(`{"name":"packageName"}`)
fs.writeFile = jest.fn<any>()

await run()

Expand Down
5 changes: 3 additions & 2 deletions packages/jest-helpers/src/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeAll, describe, expect, it, jest, test } from '@jest/globals'
import makeHelpers from '..'
import type { RenderWithThemeFn } from '../helpers/renderWithTheme'
import type { ShouldMatchEmotionSnapshotFn } from '../helpers/shouldMatchEmotionSnapshot'
Expand Down Expand Up @@ -31,7 +32,7 @@ describe('@jest-helpers', () => {
})

test('should call tranform with shouldMatchEmotionSnapshot', async () => {
const transform = jest.fn()
const transform = jest.fn<any>()
await shouldMatchEmotionSnapshot(<div id="test" />, { transform })

expect(transform).toHaveBeenCalledTimes(1)
Expand All @@ -42,7 +43,7 @@ describe('@jest-helpers', () => {
})

it('should call transform with shouldMatchEmotionSnapshot', async () => {
const transform = jest.fn()
const transform = jest.fn<any>()
await shouldMatchEmotionSnapshotWithPortal(<div id="test" />, { transform })

expect(transform).toHaveBeenCalledTimes(1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect } from '@jest/globals'
import type { RenderOptions, render } from '@testing-library/react'
import type { ReactNode } from 'react'
import type { RenderWithThemeFn } from './renderWithTheme'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, jest } from '@jest/globals'
import type { RenderOptions, render } from '@testing-library/react'
import type { ReactNode } from 'react'
import type { RenderWithThemeFn } from './renderWithTheme'
Expand Down
1 change: 1 addition & 0 deletions packages/jest-helpers/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { CreateSerializerOptions } from '@emotion/jest'
import { createSerializer } from '@emotion/jest'
import { expect } from '@jest/globals'
import type { FC, ReactNode } from 'react'
import type { RenderWithThemeFn } from './helpers/renderWithTheme'
import makeRenderWithTheme from './helpers/renderWithTheme'
Expand Down
2 changes: 2 additions & 0 deletions packages/outdated-browser/src/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { afterEach, beforeAll, describe, expect, jest, test } from '@jest/globals'

/**
* @jest-environment jsdom
*/
Expand Down
1 change: 1 addition & 0 deletions packages/random-name/src/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals'
import randomName from '..'

describe('randomName', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/regex/src/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, test } from '@jest/globals'
import {
absoluteLinuxPath,
accessKeyRegex,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, jest, test } from '@jest/globals'
import { render, renderHook, screen, waitFor } from '@testing-library/react'
import type { ReactNode } from 'react'
import DataLoaderProvider, { useDataLoaderContext } from '../DataLoaderProvider'
Expand Down Expand Up @@ -62,7 +63,7 @@ describe('DataLoaderProvider', () => {
try {
// @ts-expect-error Should throw an error
await result.current.reload(3).catch(undefined)
fail('It should throw an error')
throw new Error('It should throw an error')
} catch (error) {
expect((error as Error).message).toBe(KEY_IS_NOT_STRING_ERROR)
}
Expand All @@ -72,7 +73,7 @@ describe('DataLoaderProvider', () => {
try {
// @ts-expect-error Should throw an error
result.current.clearCachedData(3)
fail('It should throw an error')
throw new Error('It should throw an error')
} catch (error) {
expect((error as Error).message).toBe(KEY_IS_NOT_STRING_ERROR)
expect(result.current.getCachedData(TEST_KEY)).toBe(true)
Expand Down Expand Up @@ -122,7 +123,7 @@ describe('DataLoaderProvider', () => {
if (testReload) {
expect(await testReload()).toBeNull()
} else {
fail('It shoulded be defined')
throw new Error('It shoulded be defined')
}
expect(result.current.getCachedData(TEST_KEY)).toBe(null)
expect(result.current.getCachedData()).toStrictEqual({ test: null })
Expand Down
1 change: 1 addition & 0 deletions packages/use-dataloader/src/__tests__/dataloader.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, jest, test } from '@jest/globals'
import waitForExpect from 'wait-for-expect'
import { StatusEnum } from '../constants'
import DataLoader from '../dataloader'
Expand Down
1 change: 1 addition & 0 deletions packages/use-dataloader/src/__tests__/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, test } from '@jest/globals'
import { marshalQueryKey } from '../helpers'

describe('marshalQueryKey', () => {
Expand Down
15 changes: 8 additions & 7 deletions packages/use-dataloader/src/__tests__/useDataLoader.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-console */
import { describe, expect, jest, test } from '@jest/globals'
import { renderHook, waitFor } from '@testing-library/react'
import type { ReactNode } from 'react'
import DataLoaderProvider, { useDataLoaderContext } from '../DataLoaderProvider'
Expand Down Expand Up @@ -501,7 +502,7 @@ describe('useDataLoader', () => {
})

test('should call onSuccess', async () => {
const onSuccess = jest.fn()
const onSuccess = jest.fn<any>()
const { result } = renderHook(
props => useDataLoader(props.key, props.method, props.config),
{
Expand All @@ -523,8 +524,8 @@ describe('useDataLoader', () => {
})

test('should call onError', async () => {
const onSuccess = jest.fn()
const onError = jest.fn()
const onSuccess = jest.fn<any>()
const onError = jest.fn<any>()
const error = new Error('Test error')
const { result } = renderHook(
props => useDataLoader(props.key, props.method, props.config),
Expand Down Expand Up @@ -557,8 +558,8 @@ describe('useDataLoader', () => {
})

test('should override onError from Provider', async () => {
const onSuccess = jest.fn()
const onError = jest.fn()
const onSuccess = jest.fn<any>()
const onError = jest.fn<any>()
const error = new Error('Test error')
const onErrorProvider = jest.fn()
const { result } = renderHook(
Expand Down Expand Up @@ -593,7 +594,7 @@ describe('useDataLoader', () => {
})

test('should call onError from Provider', async () => {
const onSuccess = jest.fn()
const onSuccess = jest.fn<any>()
const error = new Error('Test error')
const onErrorProvider = jest.fn()
const { result } = renderHook(
Expand Down Expand Up @@ -629,7 +630,7 @@ describe('useDataLoader', () => {

test('should clear error on new response', async () => {
let success = false
const onSuccess = jest.fn()
const onSuccess = jest.fn<any>()
const onError = jest.fn(() => {
success = true
})
Expand Down
1 change: 1 addition & 0 deletions packages/use-growthbook/src/__tests__/AbTestProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-expect-error TODO: remove once Growthbook is correctly typed and export
import { GrowthBook } from '@growthbook/growthbook-react'
import { beforeEach, describe, expect, it, jest } from '@jest/globals'
import { render } from '@testing-library/react'
import type { TrackingCallback } from '../AbTestProvider'
import { AbTestProvider } from '../AbTestProvider'
Expand Down
5 changes: 2 additions & 3 deletions packages/use-growthbook/src/__tests__/useAbTestAttributes.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// @ts-expect-error TODO: remove once Growthbook is correctly typed and export
import { useGrowthBook } from '@growthbook/growthbook-react'
import { beforeEach, describe, expect, it, jest } from '@jest/globals'
import { renderHook } from '@testing-library/react'
import type { Attributes } from '../types'
import { useAbTestAttributes } from '../useAbTestAttributes'

jest.mock('@growthbook/growthbook-react', () => ({
useGrowthBook: jest.fn(),
}))
jest.mock('@growthbook/growthbook-react')

describe('useAbTestAttributes', () => {
let getAttributes: () => Attributes
Expand Down
1 change: 1 addition & 0 deletions packages/use-gtm/src/__tests__/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals'
import { fireEvent, renderHook } from '@testing-library/react'
import mockdate from 'mockdate'
import type { ReactNode } from 'react'
Expand Down
1 change: 1 addition & 0 deletions packages/use-i18n/src/__tests__/formatDate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, test } from '@jest/globals'
import type { FormatDateOptions } from '../formatDate'
import formatDate, { supportedFormats } from '../formatDate'

Expand Down
1 change: 1 addition & 0 deletions packages/use-i18n/src/__tests__/formatUnit.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, test } from '@jest/globals'
import type { FormatUnitOptions } from '../formatUnit'
import formatUnit, { supportedUnits } from '../formatUnit'

Expand Down
1 change: 1 addition & 0 deletions packages/use-i18n/src/__tests__/usei18n.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals'
import { act, renderHook, waitFor } from '@testing-library/react'
import mockdate from 'mockdate'
import type { ReactNode } from 'react'
Expand Down
5 changes: 3 additions & 2 deletions packages/use-media/src/__tests__/useMedia.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it, jest } from '@jest/globals'
import { renderHook } from '@testing-library/react'
import { useMedia } from '..'

Expand All @@ -15,7 +16,7 @@ describe('useMedia hook', () => {
callback()

Object.defineProperty(window, 'matchMedia', {
value: jest.fn().mockImplementation((query: string) => ({
value: jest.fn<any>().mockImplementation((query: string) => ({
addEventListener: mockAddEventListener,
addListener: jest.fn(),
dispatchEvent: jest.fn(),
Expand Down Expand Up @@ -43,7 +44,7 @@ describe('useMedia hook', () => {
}

Object.defineProperty(window, 'matchMedia', {
value: jest.fn().mockImplementation((query: string) => ({
value: jest.fn<any>().mockImplementation((query: string) => ({
addEventListener: mockAddEventListener,
addListener: jest.fn(),
dispatchEvent: jest.fn(),
Expand Down
1 change: 1 addition & 0 deletions packages/use-query-params/src/__tests__/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it, test } from '@jest/globals'
import { act, renderHook } from '@testing-library/react'
import type { History } from 'history'
import { createMemoryHistory } from 'history'
Expand Down
1 change: 1 addition & 0 deletions packages/use-random-name/src/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals'
import { renderHook } from '@testing-library/react'
import useRandomName from '..'

Expand Down
3 changes: 2 additions & 1 deletion packages/use-segment/src/__tests__/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeEach, describe, expect, it, jest } from '@jest/globals'
import type { Context } from '@segment/analytics-next'
import { AnalyticsBrowser } from '@segment/analytics-next'
import { renderHook, waitFor } from '@testing-library/react'
Expand Down Expand Up @@ -218,7 +219,7 @@ describe('segment hook', () => {
.spyOn(AnalyticsBrowser, 'load')
.mockResolvedValue([{} as Analytics, {} as Context])

const onEventError = jest.fn()
const onEventError = jest.fn<any>()
const onError = jest.fn()

const settings = { writeKey: 'pleasethrow' }
Expand Down
1 change: 1 addition & 0 deletions packages/use-storage/src/__tests__/index.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @jest-environment jsdom
*/

import { afterEach, describe, expect, it } from '@jest/globals'
import { act, renderHook } from '@testing-library/react'
import { useLocalStorage, useSessionStorage } from '..'

Expand Down
1 change: 1 addition & 0 deletions packages/use-storage/src/__tests__/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @jest-environment node
*/

import { describe, expect, it } from '@jest/globals'
import { act, renderHook } from '@testing-library/react/pure'
import { useLocalStorage, useSessionStorage } from '..'

Expand Down
Loading