Skip to content

Commit

Permalink
broadcastchannel mock
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalmi committed May 6, 2024
1 parent c39ea1c commit e277f2f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
27 changes: 27 additions & 0 deletions irisdb-nostr/tests/setupTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// setupTests.ts

class MockBroadcastChannel {
name: string;
listeners: Array<(event: { data: any }) => void> = [];

constructor(name: string) {
this.name = name;
}

postMessage(message: any) {
this.listeners.forEach((listener) => listener({ data: message }));
}

addEventListener(event: string, listener: (event: { data: any }) => void) {
if (event === 'message') {
this.listeners.push(listener);
}
}

close() {
this.listeners = [];
}
}

// Make MockBroadcastChannel available globally in the testing environment
global.BroadcastChannel = MockBroadcastChannel as any;
1 change: 1 addition & 0 deletions irisdb-nostr/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ export default defineConfig({
},
test: {
environment: 'jsdom',
setupFiles: ['./tests/setupTests.ts'],
},
});
31 changes: 31 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"devDependencies": {
"@types/debug": "^4.1.12",
"@types/node": "^20.12.8",
"@types/react": "^18.2.74",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
Expand Down

0 comments on commit e277f2f

Please sign in to comment.