Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Gru Tester] Add unit test for src/vanilla/utils/atomWithReset.ts #11

Open
wants to merge 1 commit into
base: gru-unit-test
Choose a base branch
from

Conversation

gru-bot
Copy link

@gru-bot gru-bot commented Sep 26, 2024

Score (skipped)

0

Source Code

Link

Value & Challenge

Field Level
topValue Important
bottomValue Important
topChallenge Moderate
bottomChallenge Moderate
Value Detail
atomWithReset:
  value: Important
  reason: This function creates a writable atom with reset functionality, involving state management logic. Errors may affect user experience or secondary business logic, making it worth unit testing.
Challenge Detail
atomWithReset:
  challenge: Moderate
  reason: The function involves conditional logic and type manipulation. It relies on external modules that are relatively easy to mock. The data structure is simple, but the logic requires handling different types of updates.

Coverage

The change in coverage value, such as: 0% -> 50%, indicates that the coverage was 0% before writing the tests and 50% after writing them.

https://web.dev/articles/ta-code-coverage

Type Change
lines
statements
branches
functions

Langsmith Link

Link

Step writeAndRunTest Overview

Index Pre Passed Test Passed Post Passed
1
2

Last Model Result

Pre

Exec

npx vitest run /jotai/src/vanilla/utils/atomWithReset.gru.test.ts (0)
�[33mThe CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.�[39m

 RUN  v2.1.1 /jotai

 ✓ |jotai| src/vanilla/utils/atomWithReset.gru.test.ts  (4 tests) 8ms

 Test Files  1 passed (1)
      Tests  4 passed (4)
   Start at  13:21:17
   Duration  2.15s (transform 421ms, setup 0ms, collect 447ms, tests 8ms, environment 550ms, prepare 192ms)

Post

pnpm test:format (0)
> jotai@2.10.0 test:format /jotai
> prettier '*.{js,json,md}' '{src,tests,benchmarks,docs}/**/*.{ts,tsx,md,mdx}' --list-different

pnpm test:types (0)
> jotai@2.10.0 test:types /jotai
> tsc --noEmit

pnpm test:lint (0)
> jotai@2.10.0 test:lint /jotai
> eslint --no-eslintrc --c .eslintrc.json '*.{js,ts}' '{src,tests,benchmarks}/**/*.{ts,tsx}'

@vangie
Copy link

vangie commented Sep 27, 2024

@coderabbitai full review

@vangie vangie self-requested a review September 27, 2024 04:31
Comment on lines +1 to +16
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { atom } from '../../vanilla.ts'
import { atomWithReset } from './atomWithReset.ts'
import { RESET } from './constants.ts'

vi.mock('../../vanilla.ts', async (importOriginal) => {
const actual = await importOriginal<typeof import('../../vanilla.ts')>()
return {
...actual,
atom: vi.fn(actual.atom),
}
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { atom } from '../../vanilla.ts'
import { atomWithReset } from './atomWithReset.ts'
import { RESET } from './constants.ts'
vi.mock('../../vanilla.ts', async (importOriginal) => {
const actual = await importOriginal<typeof import('../../vanilla.ts')>()
return {
...actual,
atom: vi.fn(actual.atom),
}
})
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { RESET, atomWithReset } from 'jotai/vanilla/utils'
vi.mock('jotai/vanilla', async (importOriginal) => {
const actual = await importOriginal<typeof import('jotai/vanilla')>()
return {
...actual,
atom: vi.fn(actual.atom),
}
})

最终过 lint 的代码是这样的。我们在这个项目里 lint 似乎没有开启。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants