Skip to content

Commit

Permalink
test(react-query): add test code for copy function (#1151)
Browse files Browse the repository at this point in the history
# Overview

- add test code for copy function

### before
<img width="816" alt="before"
src="https://github.com/user-attachments/assets/6eea0254-40d8-4a0a-8e95-f1c9cc7c82f5">

### after
<img width="816" alt="after"
src="https://github.com/user-attachments/assets/972c3196-c1c1-4520-a00e-b70c4383788e">

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md)
2. I added documents and tests.

Co-authored-by: kinndohyun <[email protected]>
Co-authored-by: GwanSik Kim <[email protected]>
  • Loading branch information
3 people authored Jul 27, 2024
1 parent d6eb8c3 commit a5b0255
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/react-query/src/scripts/utils/copy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs'
import { noop } from '@suspensive/utils'
import { copy } from './copy'

describe('copy', () => {
Expand All @@ -17,6 +18,14 @@ describe('copy', () => {
})

it('should copy and replace files with the specified version', () => {
vi.spyOn(fs, 'readdirSync').mockReturnValue(['v5', 'other'] as unknown as fs.Dirent[])
vi.spyOn(fs, 'unlinkSync').mockImplementation(noop)
vi.spyOn(fs, 'writeFileSync').mockImplementation(noop)

expect(copy(5)).toBe(true)
expect(fs.readdirSync).toHaveBeenCalledTimes(1)
expect(fs.readFileSync).toHaveBeenCalledTimes(1)
expect(fs.unlinkSync).toHaveBeenCalledTimes(1)
expect(fs.writeFileSync).toHaveBeenCalledTimes(1)
})
})

0 comments on commit a5b0255

Please sign in to comment.