From f16c4605f6854b17b429986c8854f655140d17c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gromit=20=28=EC=A0=84=EB=AF=BC=EC=9E=AC=29?= <64779472+ssi02014@users.noreply.github.com> Date: Mon, 6 Nov 2023 22:52:47 +0900 Subject: [PATCH] test(react): add useIsomorphicLayoutEffect Test Code (#303) # Overview fix: https://github.com/suspensive/react/issues/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 --- .../hooks/useIsomorphicLayoutEffect.spec.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 packages/react/src/hooks/useIsomorphicLayoutEffect.spec.ts diff --git a/packages/react/src/hooks/useIsomorphicLayoutEffect.spec.ts b/packages/react/src/hooks/useIsomorphicLayoutEffect.spec.ts new file mode 100644 index 000000000..6ac71d3d0 --- /dev/null +++ b/packages/react/src/hooks/useIsomorphicLayoutEffect.spec.ts @@ -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) + }) +})