From 818815cde6ebae1f3a3209bfd389ea325ee41dd8 Mon Sep 17 00:00:00 2001 From: Null <7566349+zhongjiayao@user.noreply.gitee.com> Date: Sat, 24 Aug 2024 16:44:23 +0800 Subject: [PATCH] =?UTF-8?q?test(hooks):=20=E6=B7=BB=E5=8A=A0useDebounce?= =?UTF-8?q?=E5=92=8CuseThrottle=E7=9A=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为useDebounce和useThrottle添加了基于jest和vue的单元测试 --- CHANGELOG.md | 3 ++- packages/hooks/src/useOnline/index.ts | 1 - .../hooks/src/useRect/__tests__/index.test.ts | 25 +++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 packages/hooks/src/useRect/__tests__/index.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 21f4aa9..3ff24f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ -## 1.0.0 (2024-08-23) +## 1.0.0 (2024-08-24) * test(hooks): 添加对useBoolean和useToggle和useTitle的单元测试 ([8951ad9](https://github.com/zjydipingxian/hooks-encode/commit/8951ad9)) +* test(hooks): 添加useDebounce和useThrottle的测试 ([2d5539a](https://github.com/zjydipingxian/hooks-encode/commit/2d5539a)) * test(hooks): 新增useThrottle的测试用例 ([8288fd3](https://github.com/zjydipingxian/hooks-encode/commit/8288fd3)) * refactor(cli): 将CLI入口文件和实用程序模块转换为TypeScript ([e2243be](https://github.com/zjydipingxian/hooks-encode/commit/e2243be)) * refactor(cli): 使用 prettier 格式化代码并更新导入逻辑 ([b626f83](https://github.com/zjydipingxian/hooks-encode/commit/b626f83)) diff --git a/packages/hooks/src/useOnline/index.ts b/packages/hooks/src/useOnline/index.ts index 9063393..1ed38fc 100644 --- a/packages/hooks/src/useOnline/index.ts +++ b/packages/hooks/src/useOnline/index.ts @@ -1,5 +1,4 @@ import { ref, onMounted, onUnmounted } from 'vue'; -import useEventListener from '../useEventListener'; /** * @description 用户网络是否可用 diff --git a/packages/hooks/src/useRect/__tests__/index.test.ts b/packages/hooks/src/useRect/__tests__/index.test.ts new file mode 100644 index 0000000..29e82da --- /dev/null +++ b/packages/hooks/src/useRect/__tests__/index.test.ts @@ -0,0 +1,25 @@ +import { describe, expect, it } from '@jest/globals'; +import { ref } from 'vue'; + +import useRect from '../index'; + +describe('useRect', () => { + it('should return the correct DOMRect for a window', () => { + const rect = useRect(window); + expect(rect.width).toEqual(window.innerWidth); + expect(rect.height).toEqual(window.innerHeight); + }); + + it('should return the correct DOMRect for an element with getBoundingClientRect', () => { + const element = document.createElement('div'); + const rect = useRect(element); + expect(rect.width).toEqual(element.getBoundingClientRect().width); + expect(rect.height).toEqual(element.getBoundingClientRect().height); + }); + + it('should return a default DOMRect for an undefined element', () => { + const rect = useRect(ref(undefined)); + expect(rect.width).toEqual(0); + expect(rect.height).toEqual(0); + }); +});