test: add case for coverage (#38018)

This commit is contained in:
lijianan 2022-10-14 14:03:01 +08:00 committed by GitHub
parent 71cfa31728
commit 82de4942d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -5,7 +5,7 @@ import accessibilityTest from '../../../tests/shared/accessibilityTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { render, triggerResize, waitFakeTimer } from '../../../tests/utils';
import Button from '../../button';
import { getObserverEntities } from '../utils';
import { addObserveTarget, getObserverEntities } from '../utils';
const events: Partial<Record<keyof HTMLElementEventMap, (ev: Partial<Event>) => void>> = {};
@ -248,5 +248,11 @@ describe('Affix Render', () => {
expect(updateCalled).toHaveBeenCalled();
});
});
it('addObserveTarget should not Throw Error when target is null', () => {
expect(() => {
addObserveTarget(null);
}).not.toThrow();
});
});
});

View File

@ -51,8 +51,10 @@ export function getObserverEntities() {
return observerEntities;
}
export function addObserveTarget<T>(target: HTMLElement | Window | null, affix: T): void {
if (!target) return;
export function addObserveTarget<T>(target: HTMLElement | Window | null, affix?: T): void {
if (!target) {
return;
}
let entity: ObserverEntity | undefined = observerEntities.find(item => item.target === target);