test: Split test utilities to improve test times (#2622)

This commit is contained in:
Dermot Duffy
2026-07-26 16:29:53 -07:00
committed by GitHub
parent 8d44fcecf1
commit ad89aa9538
234 changed files with 2730 additions and 2516 deletions
@@ -58,14 +58,14 @@ describe('LazyLoadController', () => {
it('should add controller to host', () => {
const host = createLitElement();
const controller = new LazyLoadController(host);
expect(host.addController).toBeCalledWith(controller);
expect(host.addController).toHaveBeenCalledWith(controller);
});
it('should remove controller from host', () => {
const host = createLitElement();
const controller = new LazyLoadController(host);
controller.removeController();
expect(host.removeController).toBeCalledWith(controller);
expect(host.removeController).toHaveBeenCalledWith(controller);
});
it('should remove handlers and listeners on destroy', () => {
@@ -81,8 +81,8 @@ describe('LazyLoadController', () => {
controller.destroy();
expect(getMockIntersectionObserver()?.disconnect).toBeCalled();
expect(global.document.removeEventListener).toBeCalledWith(
expect(getMockIntersectionObserver()?.disconnect).toHaveBeenCalled();
expect(global.document.removeEventListener).toHaveBeenCalledWith(
'visibilitychange',
expect.anything(),
);
@@ -90,7 +90,7 @@ describe('LazyLoadController', () => {
callVisibilityHandler(true);
callIntersectionHandler(true);
expect(listener).not.toBeCalled();
expect(listener).not.toHaveBeenCalled();
});
describe('should set configuration', () => {
@@ -100,12 +100,12 @@ describe('LazyLoadController', () => {
controller.addListener(listener);
expect(controller.isLoaded()).toBe(false);
expect(listener).not.toBeCalled();
expect(listener).not.toHaveBeenCalled();
controller.setConfiguration({ lazyLoad: false });
expect(controller.isLoaded()).toBe(true);
expect(listener).toBeCalled();
expect(listener).toHaveBeenCalled();
});
it('should re-evaluate unload when conditions change while loaded', () => {
@@ -206,8 +206,8 @@ describe('LazyLoadController', () => {
expect(controller.isLoaded()).toBe(false);
// Should also stop observing.
expect(getMockIntersectionObserver()?.disconnect).toBeCalled();
expect(global.document.removeEventListener).toBeCalledWith(
expect(getMockIntersectionObserver()?.disconnect).toHaveBeenCalled();
expect(global.document.removeEventListener).toHaveBeenCalledWith(
'visibilitychange',
expect.anything(),
);
@@ -383,19 +383,19 @@ describe('LazyLoadController', () => {
callIntersectionHandler(true);
callVisibilityHandler(true);
expect(listener).toHaveBeenLastCalledWith(true);
expect(listener).toBeCalledTimes(1);
expect(listener).toHaveBeenCalledTimes(1);
callIntersectionHandler(false);
expect(listener).toHaveBeenLastCalledWith(false);
expect(listener).toBeCalledTimes(2);
expect(listener).toHaveBeenCalledTimes(2);
callIntersectionHandler(true);
expect(listener).toHaveBeenLastCalledWith(true);
expect(listener).toBeCalledTimes(3);
expect(listener).toHaveBeenCalledTimes(3);
controller.removeListener(listener);
callIntersectionHandler(false);
expect(listener).toBeCalledTimes(3);
expect(listener).toHaveBeenCalledTimes(3);
});
});