-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
packages/taquito-beacon-wallet/test/__mocks__/broadcast-channel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
interface MessageListener { | ||
(message: any): void; | ||
} | ||
|
||
class BroadcastChannel { | ||
name: string; | ||
listeners: MessageListener[]; | ||
|
||
constructor(name: string) { | ||
this.name = name; | ||
this.listeners = []; | ||
} | ||
|
||
postMessage(message: any) { | ||
// Mock implementation of postMessage | ||
this.listeners.forEach((listener) => listener(message)); | ||
} | ||
|
||
addEventListener(event: string, listener: MessageListener) { | ||
if (event === 'message') { | ||
this.listeners.push(listener); | ||
} | ||
} | ||
|
||
removeEventListener(event: string, listener: MessageListener) { | ||
if (event === 'message') { | ||
this.listeners = this.listeners.filter((l) => l !== listener); | ||
} | ||
} | ||
|
||
close() { | ||
// Mock implementation of close | ||
this.listeners = []; | ||
} | ||
} | ||
|
||
function createLeaderElection(_channel: BroadcastChannel) { | ||
// Mock implementation of createLeaderElection | ||
return { | ||
awaitLeadership: jest.fn(), | ||
hasLeader: jest.fn().mockReturnValue(true), | ||
isLeader: jest.fn().mockReturnValue(true), | ||
die: jest.fn(), | ||
}; | ||
} | ||
|
||
export { BroadcastChannel, createLeaderElection }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters