Skip to content

Commit

Permalink
test(hooks): 添加useDebounce和useThrottle的测试
Browse files Browse the repository at this point in the history
为useDebounce和useThrottle添加了基于jest和vue的单元测试
  • Loading branch information
Null committed Aug 24, 2024
1 parent 2d5539a commit 818815c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
1 change: 0 additions & 1 deletion packages/hooks/src/useOnline/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ref, onMounted, onUnmounted } from 'vue';
import useEventListener from '../useEventListener';

/**
* @description 用户网络是否可用
Expand Down
25 changes: 25 additions & 0 deletions packages/hooks/src/useRect/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 818815c

Please sign in to comment.