ghost-keychain/__mocks__/chrome.ts
Jaco Greeff 75f9109cf4
Remove extensionizer indirection (#309)
* Remove extensionizer indirection

* Slight duplication

* Chrome mock

* Update package.json

* chrome types, chrome import
2020-04-03 13:06:25 +02:00

36 lines
861 B
TypeScript

// Copyright 2019 @polkadot/extension-ui authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
/* eslint-disable @typescript-eslint/no-explicit-any */
import chrome from 'sinon-chrome';
class MessagingFake {
private listeners: any = [];
get onMessage (): any {
return {
addListener: (cb: any): any => this.listeners.push(cb)
};
}
get onDisconnect (): any {
return {
addListener: (): any => undefined
};
}
postMessage (data: any): void {
this.listeners.forEach((cb: any) => cb.call(this, data));
}
}
const messagingFake = new MessagingFake();
chrome.runtime.connect.returns(messagingFake);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(window as any).chrome = chrome;
export default chrome;