From d470537d4406790f44db7c5e7832d557b919912b Mon Sep 17 00:00:00 2001 From: Davide Carpini Date: Tue, 21 Nov 2023 15:12:25 +0100 Subject: [PATCH] test: add vi tests --- packages/dapp-kit-ui/test/listeners.test.ts | 24 +++++++++++++++++++++ packages/dapp-kit-ui/tsconfig.json | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 packages/dapp-kit-ui/test/listeners.test.ts diff --git a/packages/dapp-kit-ui/test/listeners.test.ts b/packages/dapp-kit-ui/test/listeners.test.ts new file mode 100644 index 00000000..e0d55d37 --- /dev/null +++ b/packages/dapp-kit-ui/test/listeners.test.ts @@ -0,0 +1,24 @@ +import { vi } from 'vitest'; +import { addResizeListeners } from '../src/utils/listeners'; // Replace 'yourModule' with the actual module path + +describe('addResizeListeners', () => { + it('should call the callback when the window loads', () => { + const callback = vi.fn(); + addResizeListeners(callback); + + // Simulate a 'load' event on the window + window.dispatchEvent(new Event('load')); + + expect(callback).toHaveBeenCalled(); + }); + + it('should call the callback when the window resizes', () => { + const callback = vi.fn(); + addResizeListeners(callback); + + // Simulate a 'resize' event on the window + window.dispatchEvent(new Event('resize')); + + expect(callback).toHaveBeenCalled(); + }); +}); diff --git a/packages/dapp-kit-ui/tsconfig.json b/packages/dapp-kit-ui/tsconfig.json index 49edcff3..17cd689c 100644 --- a/packages/dapp-kit-ui/tsconfig.json +++ b/packages/dapp-kit-ui/tsconfig.json @@ -4,6 +4,6 @@ "target": "es2021", "experimentalDecorators": true }, - "include": ["src/**/*.ts"], + "include": ["src/**/*.ts", "test/listeners.test.ts"], "exclude": [] }