Skip to content

Commit

Permalink
test(react): add useIsomorphicLayoutEffect Test Code (#303)
Browse files Browse the repository at this point in the history
# Overview

fix: #302

## PR Checklist

- [x] I did below actions if need

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

---------

Co-authored-by: Jonghyeon Ko <[email protected]>
  • Loading branch information
ssi02014 and Jonghyeon Ko authored Nov 6, 2023
1 parent 3fc3249 commit f16c460
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/react/src/hooks/useIsomorphicLayoutEffect.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useEffect, useLayoutEffect } from 'react'
import { afterEach, expect, vi } from 'vitest'

describe('useIsomorphicLayoutEffect', () => {
const originWindow = global.window

afterEach(() => {
vi.resetModules()
})

it('should be useEffect in server environment', async () => {
Object.defineProperty(global, 'window', {
value: undefined,
})

const { useIsomorphicLayoutEffect } = await import('./useIsomorphicLayoutEffect')
expect(useIsomorphicLayoutEffect).toEqual(useEffect)
})

it('should be useLayoutEffect in client environment', async () => {
Object.defineProperty(global, 'window', {
value: originWindow,
})

const { useIsomorphicLayoutEffect } = await import('./useIsomorphicLayoutEffect')
expect(useIsomorphicLayoutEffect).toEqual(useLayoutEffect)
})
})

2 comments on commit f16c460

@vercel
Copy link

@vercel vercel bot commented on f16c460 Nov 6, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on f16c460 Nov 6, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

visualization – ./websites/visualization

visualization-git-main-suspensive.vercel.app
visualization-suspensive.vercel.app
visualization.suspensive.org

Please sign in to comment.