-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(hooks): 添加useDebounce和useThrottle的测试
为useDebounce和useThrottle添加了基于jest和vue的单元测试
- Loading branch information
Null
committed
Aug 24, 2024
1 parent
2d5539a
commit 818815c
Showing
3 changed files
with
27 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |