Skip to content

Commit

Permalink
fix: make onUserInput export optional
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed Apr 30, 2024
1 parent 4fe10a6 commit ea7596d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,47 @@ describe('BaseSnapExecutor', () => {
});
});

it('returns null if no onUserInput export is found', async () => {
const CODE = `
module.exports.onRpcRequest = () => {}
`;

const executor = new TestSnapExecutor();
await executor.executeSnap(1, MOCK_SNAP_ID, CODE, []);

expect(await executor.readCommand()).toStrictEqual({
jsonrpc: '2.0',
id: 1,
result: 'OK',
});

const params = {
id: 'foo',
event: {
type: UserInputEventType.ButtonClickEvent,
name: 'bar',
},
};

await executor.writeCommand({
jsonrpc: '2.0',
id: 2,
method: 'snapRpc',
params: [
MOCK_SNAP_ID,
HandlerType.OnUserInput,
MOCK_ORIGIN,
{ jsonrpc: '2.0', method: 'foo', params },
],
});

expect(await executor.readCommand()).toStrictEqual({
id: 2,
jsonrpc: '2.0',
result: null,
});
});

describe('lifecycle hooks', () => {
const LIFECYCLE_HOOKS = [HandlerType.OnInstall, HandlerType.OnUpdate];

Expand Down
2 changes: 1 addition & 1 deletion packages/snaps-utils/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const SNAP_EXPORTS = {
},
[HandlerType.OnUserInput]: {
type: HandlerType.OnUserInput,
required: true,
required: false,
validator: (snapExport: unknown): snapExport is OnUserInputHandler => {
return typeof snapExport === 'function';
},
Expand Down

0 comments on commit ea7596d

Please sign in to comment.