Skip to content

Commit

Permalink
fix file
Browse files Browse the repository at this point in the history
  • Loading branch information
scurker committed Sep 20, 2024
1 parent 63493f7 commit fa32608
Showing 1 changed file with 7 additions and 7 deletions.
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);
});

0 comments on commit fa32608

Please sign in to comment.