-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
7 additions
and
7 deletions.
There are no files selected for viewing
14 changes: 7 additions & 7 deletions
14
...s/react/src/utils/getElementOrRef.test.ts → ...es/react/src/utils/resolveElement.test.ts
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 |
---|---|---|
@@ -1,33 +1,33 @@ | ||
import { createRef, type MutableRefObject } from 'react'; | ||
import getElementOrRef from './getElementOrRef'; | ||
import resolveElement from './resolveElement'; | ||
|
||
test('should return element', () => { | ||
expect(getElementOrRef(document.body)).toBe(document.body); | ||
expect(resolveElement(document.body)).toBe(document.body); | ||
}); | ||
|
||
test('should return ref element', () => { | ||
const ref = createRef() as MutableRefObject<HTMLElement>; | ||
ref.current = document.body; | ||
expect(getElementOrRef(ref)).toBe(document.body); | ||
expect(resolveElement(ref)).toBe(document.body); | ||
}); | ||
|
||
test('should return null when element is undefined', () => { | ||
expect(getElementOrRef(undefined)).toBe(null); | ||
expect(resolveElement(undefined)).toBe(null); | ||
}); | ||
|
||
test('should return null when ref is undefined', () => { | ||
const ref = createRef() as MutableRefObject<HTMLElement>; | ||
expect(getElementOrRef(ref)).toBe(null); | ||
expect(resolveElement(ref)).toBe(null); | ||
}); | ||
|
||
test('should return null when element is not instance of Element', () => { | ||
// @ts-expect-error bad data | ||
expect(getElementOrRef('thing')).toBe(null); | ||
expect(resolveElement('thing')).toBe(null); | ||
}); | ||
|
||
test('should return null when ref is not instance of Element', () => { | ||
const ref = createRef() as MutableRefObject<HTMLElement>; | ||
// @ts-expect-error bad data | ||
ref.current = 'thing'; | ||
expect(getElementOrRef(ref)).toBe(null); | ||
expect(resolveElement(ref)).toBe(null); | ||
}); |