Skip to content

Commit 49825c2

Browse files
Fix test
1 parent e87ff3c commit 49825c2

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

packages/snaps-controllers/src/services/webview/WebViewMessageStream.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ describe('WebViewMessageStream', () => {
2222
expect(await responsePromise).toBe(555);
2323

2424
expect(mockWebViewA.injectJavaScript).toHaveBeenCalledWith(
25-
`window.postMessage('eyJ0YXJnZXQiOiJiIiwiZGF0YSI6MTExfQ==')`,
25+
`window.postMessage([123,34,116,97,114,103,101,116,34,58,34,98,34,44,34,100,97,116,97,34,58,34,83,89,78,34,125])`,
2626
);
2727

2828
// Inject { target: "foo", data: 111 }
2929
mockWebViewA.injectJavaScript(
30-
`window.postMessage('eyJ0YXJnZXQiOiJmb28iLCJkYXRhIjoxMTF9')`,
30+
`window.postMessage([123,34,116,97,114,103,101,116,34,58,34,102,111,111,34,44,34,100,97,116,97,34,58,49,49,49,125])`,
3131
);
3232

3333
const listener = jest.fn();

packages/snaps-controllers/src/test-utils/webview.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { base64ToBytes, bytesToString } from '@metamask/utils';
1+
import { bytesToString } from '@metamask/utils';
22

33
import { WebViewMessageStream } from '../services/webview/WebViewMessageStream';
44

55
/**
6-
* Parses the injected JS and returns the decoded base64 payload.
6+
* Parses the injected JS and returns the JSON payload.
77
*
88
* @param js - The injected JS.
9-
* @returns The parsed base64 payload as a string.
9+
* @returns The decoded JSON as a string.
1010
*/
1111
export function parseInjectedJS(js: string) {
12-
const base64 = js.slice(20, -2);
13-
const bytes = base64ToBytes(base64);
12+
const byteString = js.slice(19, -1);
13+
const bytes = new Uint8Array(JSON.parse(byteString));
1414
return bytesToString(bytes);
1515
}
1616

0 commit comments

Comments
 (0)