@metamask/snaps-jest 6.0.2 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/README.md +100 -7
  3. package/dist/{chunk-6RXFM4YC.js → chunk-2JAGD4N6.js} +3 -3
  4. package/dist/{chunk-7YD4IW43.mjs → chunk-3M4GRUMH.mjs} +3 -6
  5. package/dist/chunk-3M4GRUMH.mjs.map +1 -0
  6. package/dist/{chunk-7BFTEFLS.mjs → chunk-5U5WB3SM.mjs} +5 -3
  7. package/dist/chunk-5U5WB3SM.mjs.map +1 -0
  8. package/dist/chunk-6POKT4OO.js +127 -0
  9. package/dist/chunk-6POKT4OO.js.map +1 -0
  10. package/dist/{chunk-7VILST6M.mjs → chunk-BVGI3E45.mjs} +2 -2
  11. package/dist/chunk-CKRORVDW.js +1 -0
  12. package/dist/{chunk-6HW5NGCB.js → chunk-DTDYOBCI.js} +3 -3
  13. package/dist/{chunk-WIFOID2P.mjs → chunk-EDEJD326.mjs} +20 -10
  14. package/dist/chunk-EDEJD326.mjs.map +1 -0
  15. package/dist/{chunk-B4QZXXQY.js → chunk-FIZAYEHV.js} +4 -4
  16. package/dist/chunk-I5P52IMF.mjs +223 -0
  17. package/dist/chunk-I5P52IMF.mjs.map +1 -0
  18. package/dist/{chunk-T2BE4O5H.js → chunk-IDGD7TZ7.js} +33 -23
  19. package/dist/chunk-IDGD7TZ7.js.map +1 -0
  20. package/dist/{chunk-BS24WMRW.mjs → chunk-LG3VKXGH.mjs} +2 -2
  21. package/dist/{chunk-C2ONPIIB.js → chunk-MCYTJUDG.js} +10 -15
  22. package/dist/chunk-MCYTJUDG.js.map +1 -0
  23. package/dist/chunk-PVMIH6OB.mjs +127 -0
  24. package/dist/chunk-PVMIH6OB.mjs.map +1 -0
  25. package/dist/chunk-S2HLITUN.js +1 -0
  26. package/dist/{chunk-ISWZ7XZ5.js → chunk-SB5EPHE3.js} +5 -3
  27. package/dist/chunk-SB5EPHE3.js.map +1 -0
  28. package/dist/{chunk-HBLJOACO.mjs → chunk-TAIJXTLU.mjs} +2 -10
  29. package/dist/chunk-TAIJXTLU.mjs.map +1 -0
  30. package/dist/chunk-TGZ7WOTJ.mjs +1 -0
  31. package/dist/chunk-UDOXICJK.mjs +1 -0
  32. package/dist/{chunk-3HU56QS3.mjs → chunk-VSUNWJMQ.mjs} +8 -13
  33. package/dist/chunk-VSUNWJMQ.mjs.map +1 -0
  34. package/dist/{chunk-TO46ICOZ.js → chunk-WMLSD6B5.js} +3 -6
  35. package/dist/chunk-WMLSD6B5.js.map +1 -0
  36. package/dist/{chunk-3SNZ4SPY.mjs → chunk-X5IPMTHO.mjs} +2 -2
  37. package/dist/chunk-Y4DKEF7Y.js +223 -0
  38. package/dist/chunk-Y4DKEF7Y.js.map +1 -0
  39. package/dist/{chunk-7J34R6YW.mjs → chunk-YEVKBYKO.mjs} +35 -25
  40. package/dist/chunk-YEVKBYKO.mjs.map +1 -0
  41. package/dist/{chunk-5PLDD7ZC.js → chunk-Z35PCKFD.js} +24 -14
  42. package/dist/chunk-Z35PCKFD.js.map +1 -0
  43. package/dist/{chunk-LXSNRZV4.js → chunk-ZWN4SO2V.js} +5 -13
  44. package/dist/chunk-ZWN4SO2V.js.map +1 -0
  45. package/dist/environment.js +13 -14
  46. package/dist/environment.mjs +12 -13
  47. package/dist/global.js +2 -0
  48. package/dist/global.js.map +1 -0
  49. package/dist/global.mjs +2 -0
  50. package/dist/global.mjs.map +1 -0
  51. package/dist/helpers.js +13 -14
  52. package/dist/helpers.mjs +12 -13
  53. package/dist/index.js +16 -16
  54. package/dist/index.mjs +15 -15
  55. package/dist/internals/index.js +27 -14
  56. package/dist/internals/index.mjs +30 -17
  57. package/dist/internals/request.js +12 -11
  58. package/dist/internals/request.mjs +13 -12
  59. package/dist/internals/simulation/controllers.js +6 -7
  60. package/dist/internals/simulation/controllers.mjs +5 -6
  61. package/dist/internals/simulation/index.js +17 -10
  62. package/dist/internals/simulation/index.mjs +17 -10
  63. package/dist/internals/simulation/interface.js +11 -3
  64. package/dist/internals/simulation/interface.mjs +12 -4
  65. package/dist/internals/simulation/methods/hooks/index.js +4 -10
  66. package/dist/internals/simulation/methods/hooks/index.mjs +3 -9
  67. package/dist/internals/simulation/methods/hooks/notifications.js +1 -1
  68. package/dist/internals/simulation/methods/hooks/notifications.mjs +1 -1
  69. package/dist/internals/simulation/methods/hooks/show-dialog.js +1 -1
  70. package/dist/internals/simulation/methods/hooks/show-dialog.mjs +1 -1
  71. package/dist/internals/simulation/methods/hooks/state.js +3 -3
  72. package/dist/internals/simulation/methods/hooks/state.mjs +2 -2
  73. package/dist/internals/simulation/methods/index.js +5 -6
  74. package/dist/internals/simulation/methods/index.mjs +4 -5
  75. package/dist/internals/simulation/methods/specifications.js +5 -6
  76. package/dist/internals/simulation/methods/specifications.mjs +4 -5
  77. package/dist/internals/simulation/simulation.js +8 -9
  78. package/dist/internals/simulation/simulation.mjs +7 -8
  79. package/dist/internals/simulation/store/index.js +2 -2
  80. package/dist/internals/simulation/store/index.mjs +1 -1
  81. package/dist/internals/simulation/store/store.js +2 -2
  82. package/dist/internals/simulation/store/store.mjs +1 -1
  83. package/dist/internals/structs.js +6 -2
  84. package/dist/internals/structs.mjs +5 -1
  85. package/dist/matchers.js +13 -14
  86. package/dist/matchers.mjs +12 -13
  87. package/dist/setup.js +12 -13
  88. package/dist/setup.mjs +12 -13
  89. package/dist/tsconfig.build.tsbuildinfo +1 -1
  90. package/dist/types/global.d.ts +69 -0
  91. package/dist/types/index.d.ts +1 -0
  92. package/dist/types/internals/request.d.ts +13 -4
  93. package/dist/types/internals/simulation/interface.d.ts +47 -4
  94. package/dist/types/internals/simulation/methods/hooks/index.d.ts +0 -1
  95. package/dist/types/internals/simulation/methods/hooks/state.d.ts +2 -1
  96. package/dist/types/internals/simulation/store/store.d.ts +1 -2
  97. package/dist/types/internals/structs.d.ts +79 -156
  98. package/dist/types/types.d.ts +42 -21
  99. package/package.json +6 -6
  100. package/dist/chunk-2X23DUDP.mjs +0 -22
  101. package/dist/chunk-2X23DUDP.mjs.map +0 -1
  102. package/dist/chunk-3HU56QS3.mjs.map +0 -1
  103. package/dist/chunk-5PLDD7ZC.js.map +0 -1
  104. package/dist/chunk-6MVV44M5.mjs +0 -76
  105. package/dist/chunk-6MVV44M5.mjs.map +0 -1
  106. package/dist/chunk-7BFTEFLS.mjs.map +0 -1
  107. package/dist/chunk-7J34R6YW.mjs.map +0 -1
  108. package/dist/chunk-7YD4IW43.mjs.map +0 -1
  109. package/dist/chunk-C2ONPIIB.js.map +0 -1
  110. package/dist/chunk-HBLJOACO.mjs.map +0 -1
  111. package/dist/chunk-HNH5UAKZ.js +0 -80
  112. package/dist/chunk-HNH5UAKZ.js.map +0 -1
  113. package/dist/chunk-ISWZ7XZ5.js.map +0 -1
  114. package/dist/chunk-LXSNRZV4.js.map +0 -1
  115. package/dist/chunk-LYK6EGZU.mjs +0 -80
  116. package/dist/chunk-LYK6EGZU.mjs.map +0 -1
  117. package/dist/chunk-RD7GQCPL.js +0 -22
  118. package/dist/chunk-RD7GQCPL.js.map +0 -1
  119. package/dist/chunk-T2BE4O5H.js.map +0 -1
  120. package/dist/chunk-TO46ICOZ.js.map +0 -1
  121. package/dist/chunk-U5BLLHIU.js +0 -1
  122. package/dist/chunk-V6LFAN3U.mjs +0 -1
  123. package/dist/chunk-WIFOID2P.mjs.map +0 -1
  124. package/dist/chunk-ZAQZRYPW.js +0 -76
  125. package/dist/chunk-ZAQZRYPW.js.map +0 -1
  126. package/dist/internals/simulation/methods/hooks/encryption.js +0 -10
  127. package/dist/internals/simulation/methods/hooks/encryption.mjs +0 -10
  128. package/dist/types/internals/simulation/methods/hooks/encryption.d.ts +0 -29
  129. /package/dist/{chunk-6RXFM4YC.js.map → chunk-2JAGD4N6.js.map} +0 -0
  130. /package/dist/{chunk-7VILST6M.mjs.map → chunk-BVGI3E45.mjs.map} +0 -0
  131. /package/dist/{chunk-U5BLLHIU.js.map → chunk-CKRORVDW.js.map} +0 -0
  132. /package/dist/{chunk-6HW5NGCB.js.map → chunk-DTDYOBCI.js.map} +0 -0
  133. /package/dist/{chunk-B4QZXXQY.js.map → chunk-FIZAYEHV.js.map} +0 -0
  134. /package/dist/{chunk-BS24WMRW.mjs.map → chunk-LG3VKXGH.mjs.map} +0 -0
  135. /package/dist/{internals/simulation/methods/hooks/encryption.js.map → chunk-S2HLITUN.js.map} +0 -0
  136. /package/dist/{chunk-V6LFAN3U.mjs.map → chunk-TGZ7WOTJ.mjs.map} +0 -0
  137. /package/dist/{internals/simulation/methods/hooks/encryption.mjs.map → chunk-UDOXICJK.mjs.map} +0 -0
  138. /package/dist/{chunk-3SNZ4SPY.mjs.map → chunk-X5IPMTHO.mjs.map} +0 -0
@@ -0,0 +1,69 @@
1
+ import type { Component, EnumToUnion, NotificationType } from '@metamask/snaps-sdk';
2
+ interface SnapsMatchers {
3
+ /**
4
+ * Assert that the response is a JSON-RPC response with the given result. This
5
+ * is equivalent to calling `expect(response.result).toStrictEqual(result)`.
6
+ *
7
+ * @param response - The expected response result.
8
+ * @throws If the response is not a JSON-RPC response with the given result.
9
+ * @example
10
+ * const response = await request({ method: 'foo' });
11
+ * expect(response).toRespondWith('bar');
12
+ */
13
+ toRespondWith(response: unknown): void;
14
+ /**
15
+ * Assert that the response is a JSON-RPC response with the given error. This
16
+ * is equivalent to calling `expect(response.error).toStrictEqual(error)`.
17
+ *
18
+ * @param error - The expected response error.
19
+ * @throws If the response is not a JSON-RPC response with the given error.
20
+ * @example
21
+ * const response = await request({ method: 'foo' });
22
+ * expect(response).toRespondWithError({
23
+ * code: -32601,
24
+ * message: 'The method does not exist / is not available.',
25
+ * stack: expect.any(String),
26
+ * data: { method: 'foo', cause: null },
27
+ * });
28
+ */
29
+ toRespondWithError(error: unknown): void;
30
+ /**
31
+ * Assert that the Snap sent a notification with the expected message, and
32
+ * optionally the expected notification type. This is equivalent to calling
33
+ * `expect(response.notifications).toContainEqual({ message, type })`.
34
+ *
35
+ * @param message - The expected notification message.
36
+ * @param type - The expected notification type, i.e., 'inApp' or 'native'. If
37
+ * not provided, the type will be ignored.
38
+ * @throws If the snap did not send a notification with the expected message.
39
+ * @example
40
+ * const response = await request({ method: 'foo' });
41
+ * expect(response).toSendNotification('bar', NotificationType.InApp);
42
+ */
43
+ toSendNotification(message: string, type?: EnumToUnion<NotificationType>): void;
44
+ /**
45
+ * Assert that the Snap rendered the expected component. This is equivalent to
46
+ * calling `expect(interface.content).toStrictEqual(component)`.
47
+ *
48
+ * @param component - The expected rendered component.
49
+ * @throws If the snap did not render the expected component.
50
+ * @example
51
+ * const response = request({ method: 'foo' });
52
+ * const ui = await response.getInterface();
53
+ * expect(ui).toRender(panel([heading('Hello, world!')]));
54
+ */
55
+ toRender(component: Component): void;
56
+ }
57
+ declare module 'expect' {
58
+ interface AsymmetricMatchers extends SnapsMatchers {
59
+ }
60
+ interface Matchers<R> extends SnapsMatchers {
61
+ }
62
+ }
63
+ declare global {
64
+ namespace jest {
65
+ interface Matchers<R> extends SnapsMatchers {
66
+ }
67
+ }
68
+ }
69
+ export {};
@@ -1,3 +1,4 @@
1
+ import './global';
1
2
  export { default, default as TestEnvironment } from './environment';
2
3
  export * from './helpers';
3
4
  export * from './options';
@@ -1,7 +1,7 @@
1
1
  import type { AbstractExecutionService } from '@metamask/snaps-controllers';
2
- import type { SnapId, Component } from '@metamask/snaps-sdk';
2
+ import type { SnapId } from '@metamask/snaps-sdk';
3
3
  import type { HandlerType } from '@metamask/snaps-utils';
4
- import type { RequestOptions, SnapRequest } from '../types';
4
+ import type { RequestOptions, SnapHandlerInterface, SnapRequest } from '../types';
5
5
  import type { RunSagaFunction, Store } from './simulation';
6
6
  import type { RootControllerMessenger } from './simulation/controllers';
7
7
  export declare type HandleRequestOptions = {
@@ -35,11 +35,20 @@ export declare type HandleRequestOptions = {
35
35
  */
36
36
  export declare function handleRequest({ snapId, store, executionService, handler, controllerMessenger, runSaga, request: { id, origin, ...options }, }: HandleRequestOptions): SnapRequest;
37
37
  /**
38
- * Get the response content either from the SnapInterfaceController or the response object if there is one.
38
+ * Get the interface ID from the result if it's available or create a new interface if the result contains static components.
39
+ *
40
+ * @param result - The handler result object.
41
+ * @param snapId - The Snap ID.
42
+ * @param controllerMessenger - The controller messenger.
43
+ * @returns The interface ID or undefined if the result doesn't include content.
44
+ */
45
+ export declare function getInterfaceFromResult(result: unknown, snapId: SnapId, controllerMessenger: RootControllerMessenger): Promise<string | undefined>;
46
+ /**
47
+ * Get the response content from the SnapInterfaceController and include the interaction methods.
39
48
  *
40
49
  * @param result - The handler result object.
41
50
  * @param snapId - The Snap ID.
42
51
  * @param controllerMessenger - The controller messenger.
43
52
  * @returns The content components if any.
44
53
  */
45
- export declare function getContentFromResult(result: unknown, snapId: SnapId, controllerMessenger: RootControllerMessenger): Component | undefined;
54
+ export declare function getInterfaceApi(result: unknown, snapId: SnapId, controllerMessenger: RootControllerMessenger): Promise<(() => SnapHandlerInterface) | undefined>;
@@ -1,7 +1,7 @@
1
- import type { Component, SnapId } from '@metamask/snaps-sdk';
1
+ import type { Button, Component, Input, InterfaceState, SnapId } from '@metamask/snaps-sdk';
2
2
  import { DialogType } from '@metamask/snaps-sdk';
3
- import type { SagaIterator } from 'redux-saga';
4
- import type { SnapInterface } from '../../types';
3
+ import { type SagaIterator } from 'redux-saga';
4
+ import type { SnapInterface, SnapInterfaceActions } from '../../types';
5
5
  import type { RootControllerMessenger } from './controllers';
6
6
  import type { RunSagaFunction } from './store';
7
7
  /**
@@ -10,9 +10,52 @@ import type { RunSagaFunction } from './store';
10
10
  * @param runSaga - A function to run a saga outside the usual Redux flow.
11
11
  * @param type - The type of the interface.
12
12
  * @param content - The content to show in the interface.
13
+ * @param interfaceActions - The actions to interact with the interface.
13
14
  * @returns The user interface object.
14
15
  */
15
- export declare function getInterfaceResponse(runSaga: RunSagaFunction, type: DialogType, content: Component): SnapInterface;
16
+ export declare function getInterfaceResponse(runSaga: RunSagaFunction, type: DialogType, content: Component, interfaceActions: SnapInterfaceActions): SnapInterface;
17
+ /**
18
+ * Get a Button or an Input from an interface.
19
+ *
20
+ * @param content - The interface content.
21
+ * @param name - The element name.
22
+ * @returns An object containing the element and the form name if it's contained in a form, otherwise undefined.
23
+ */
24
+ export declare function getElement(content: Component, name: string): {
25
+ element: Button | Input;
26
+ form?: string;
27
+ } | undefined;
28
+ /**
29
+ * Click on an element of the Snap interface.
30
+ *
31
+ * @param controllerMessenger - The controller messenger used to call actions.
32
+ * @param id - The interface ID.
33
+ * @param content - The interface content.
34
+ * @param snapId - The Snap ID.
35
+ * @param name - The element name.
36
+ */
37
+ export declare function clickElement(controllerMessenger: RootControllerMessenger, id: string, content: Component, snapId: SnapId, name: string): Promise<void>;
38
+ /**
39
+ * Merge a value in the interface state.
40
+ *
41
+ * @param state - The actual interface state.
42
+ * @param name - The component name that changed value.
43
+ * @param value - The new value.
44
+ * @param form - The form name if the element is in one.
45
+ * @returns The state with the merged value.
46
+ */
47
+ export declare function mergeValue(state: InterfaceState, name: string, value: string | null, form?: string): InterfaceState;
48
+ /**
49
+ * Type a value in an interface element.
50
+ *
51
+ * @param controllerMessenger - The controller messenger used to call actions.
52
+ * @param id - The interface ID.
53
+ * @param content - The interface Components.
54
+ * @param snapId - The Snap ID.
55
+ * @param name - The element name.
56
+ * @param value - The value to type in the element.
57
+ */
58
+ export declare function typeInField(controllerMessenger: RootControllerMessenger, id: string, content: Component, snapId: SnapId, name: string, value: string): Promise<void>;
16
59
  /**
17
60
  * Get a user interface object from a Snap.
18
61
  *
@@ -1,4 +1,3 @@
1
- export * from './encryption';
2
1
  export * from './get-locale';
3
2
  export * from './notifications';
4
3
  export * from './show-dialog';
@@ -1,3 +1,4 @@
1
+ import type { Json } from '@metamask/utils';
1
2
  import type { RunSagaFunction } from '../../store';
2
3
  /**
3
4
  * Get the implementation of the `getSnapState` hook.
@@ -12,7 +13,7 @@ export declare function getGetSnapStateMethodImplementation(runSaga: RunSagaFunc
12
13
  * @param runSaga - The function to run a saga outside the usual Redux flow.
13
14
  * @returns The implementation of the `updateSnapState` hook.
14
15
  */
15
- export declare function getUpdateSnapStateMethodImplementation(runSaga: RunSagaFunction): (_snapId: string, newState: string, encrypted?: boolean | undefined) => void;
16
+ export declare function getUpdateSnapStateMethodImplementation(runSaga: RunSagaFunction): (_snapId: string, newState: Record<string, Json>, encrypted?: boolean | undefined) => void;
16
17
  /**
17
18
  * Get the implementation of the `clearSnapState` hook.
18
19
  *
@@ -2,13 +2,12 @@ import type { SimulationOptions } from '../options';
2
2
  /**
3
3
  * Create a Redux store.
4
4
  *
5
- * @param password - The password to use for state encryption.
6
5
  * @param options - The simulation options.
7
6
  * @param options.state - The initial state for the Snap.
8
7
  * @param options.unencryptedState - The initial unencrypted state for the Snap.
9
8
  * @returns A Redux store with the default state.
10
9
  */
11
- export declare function createStore(password: string, { state, unencryptedState }: SimulationOptions): {
10
+ export declare function createStore({ state, unencryptedState }: SimulationOptions): {
12
11
  store: import("@reduxjs/toolkit/dist/configureStore").ToolkitStore<{
13
12
  mocks: import("./mocks").MocksState;
14
13
  notifications: import("./notifications").NotificationsState;
@@ -105,49 +105,13 @@ export declare const JsonRpcMockOptionsStruct: import("superstruct").Struct<{
105
105
  }>;
106
106
  export declare const InterfaceStruct: import("superstruct").Struct<{
107
107
  content?: import("@metamask/snaps-sdk").Panel | {
108
- value: string;
109
- type: import("@metamask/snaps-sdk").NodeType.Copyable;
110
- sensitive?: boolean | undefined;
111
- } | {
112
- type: import("@metamask/snaps-sdk").NodeType.Divider;
113
- } | {
114
- value: string;
115
- type: import("@metamask/snaps-sdk").NodeType.Heading;
116
- } | {
117
- value: string;
118
- type: import("@metamask/snaps-sdk").NodeType.Image;
119
- } | {
120
- type: import("@metamask/snaps-sdk").NodeType.Spinner;
121
- } | {
122
- value: string;
123
- type: import("@metamask/snaps-sdk").NodeType.Text;
124
- markdown?: boolean | undefined;
125
- } | {
126
- value: `0x${string}`;
127
- type: import("@metamask/snaps-sdk").NodeType.Address;
128
- } | {
129
- value: {
130
- value: string;
131
- type: import("@metamask/snaps-sdk").NodeType.Image;
132
- } | {
133
- value: string;
134
- type: import("@metamask/snaps-sdk").NodeType.Text;
135
- markdown?: boolean | undefined;
136
- } | {
137
- value: `0x${string}`;
138
- type: import("@metamask/snaps-sdk").NodeType.Address;
139
- };
140
- type: import("@metamask/snaps-sdk").NodeType.Row;
141
- label: string;
142
- variant?: "default" | "warning" | "critical" | undefined;
143
- } | {
144
108
  type: import("@metamask/snaps-sdk").NodeType.Input;
145
109
  name: string;
146
110
  value?: string | undefined;
147
111
  error?: string | undefined;
148
- label?: string | undefined;
149
112
  inputType?: "number" | "text" | "password" | undefined;
150
113
  placeholder?: string | undefined;
114
+ label?: string | undefined;
151
115
  } | {
152
116
  value: string;
153
117
  type: import("@metamask/snaps-sdk").NodeType.Button;
@@ -162,9 +126,9 @@ export declare const InterfaceStruct: import("superstruct").Struct<{
162
126
  name: string;
163
127
  value?: string | undefined;
164
128
  error?: string | undefined;
165
- label?: string | undefined;
166
129
  inputType?: "number" | "text" | "password" | undefined;
167
130
  placeholder?: string | undefined;
131
+ label?: string | undefined;
168
132
  } | {
169
133
  value: string;
170
134
  type: import("@metamask/snaps-sdk").NodeType.Button;
@@ -172,9 +136,7 @@ export declare const InterfaceStruct: import("superstruct").Struct<{
172
136
  variant?: "primary" | "secondary" | undefined;
173
137
  buttonType?: "button" | "submit" | undefined;
174
138
  })[];
175
- } | undefined;
176
- }, {
177
- content: import("superstruct").Struct<import("@metamask/snaps-sdk").Panel | {
139
+ } | {
178
140
  value: string;
179
141
  type: import("@metamask/snaps-sdk").NodeType.Copyable;
180
142
  sensitive?: boolean | undefined;
@@ -210,14 +172,16 @@ export declare const InterfaceStruct: import("superstruct").Struct<{
210
172
  type: import("@metamask/snaps-sdk").NodeType.Row;
211
173
  label: string;
212
174
  variant?: "default" | "warning" | "critical" | undefined;
213
- } | {
175
+ } | undefined;
176
+ }, {
177
+ content: import("superstruct").Struct<import("@metamask/snaps-sdk").Panel | {
214
178
  type: import("@metamask/snaps-sdk").NodeType.Input;
215
179
  name: string;
216
180
  value?: string | undefined;
217
181
  error?: string | undefined;
218
- label?: string | undefined;
219
182
  inputType?: "number" | "text" | "password" | undefined;
220
183
  placeholder?: string | undefined;
184
+ label?: string | undefined;
221
185
  } | {
222
186
  value: string;
223
187
  type: import("@metamask/snaps-sdk").NodeType.Button;
@@ -232,9 +196,9 @@ export declare const InterfaceStruct: import("superstruct").Struct<{
232
196
  name: string;
233
197
  value?: string | undefined;
234
198
  error?: string | undefined;
235
- label?: string | undefined;
236
199
  inputType?: "number" | "text" | "password" | undefined;
237
200
  placeholder?: string | undefined;
201
+ label?: string | undefined;
238
202
  } | {
239
203
  value: string;
240
204
  type: import("@metamask/snaps-sdk").NodeType.Button;
@@ -242,21 +206,7 @@ export declare const InterfaceStruct: import("superstruct").Struct<{
242
206
  variant?: "primary" | "secondary" | undefined;
243
207
  buttonType?: "button" | "submit" | undefined;
244
208
  })[];
245
- } | undefined, null>;
246
- }>;
247
- export declare const SnapResponseStruct: import("superstruct").Struct<{
248
- response: {
249
- result: import("@metamask/snaps-sdk").Json;
250
209
  } | {
251
- error: import("@metamask/snaps-sdk").Json;
252
- };
253
- id: string;
254
- notifications: {
255
- message: string;
256
- type: "native" | "inApp";
257
- id: string;
258
- }[];
259
- content?: import("@metamask/snaps-sdk").Panel | {
260
210
  value: string;
261
211
  type: import("@metamask/snaps-sdk").NodeType.Copyable;
262
212
  sensitive?: boolean | undefined;
@@ -292,39 +242,20 @@ export declare const SnapResponseStruct: import("superstruct").Struct<{
292
242
  type: import("@metamask/snaps-sdk").NodeType.Row;
293
243
  label: string;
294
244
  variant?: "default" | "warning" | "critical" | undefined;
245
+ } | undefined, null>;
246
+ }>;
247
+ export declare const SnapResponseWithoutInterfaceStruct: import("superstruct").Struct<{
248
+ response: {
249
+ result: import("@metamask/snaps-sdk").Json;
295
250
  } | {
296
- type: import("@metamask/snaps-sdk").NodeType.Input;
297
- name: string;
298
- value?: string | undefined;
299
- error?: string | undefined;
300
- label?: string | undefined;
301
- inputType?: "number" | "text" | "password" | undefined;
302
- placeholder?: string | undefined;
303
- } | {
304
- value: string;
305
- type: import("@metamask/snaps-sdk").NodeType.Button;
306
- name?: string | undefined;
307
- variant?: "primary" | "secondary" | undefined;
308
- buttonType?: "button" | "submit" | undefined;
309
- } | {
310
- type: import("@metamask/snaps-sdk").NodeType.Form;
311
- name: string;
312
- children: ({
313
- type: import("@metamask/snaps-sdk").NodeType.Input;
314
- name: string;
315
- value?: string | undefined;
316
- error?: string | undefined;
317
- label?: string | undefined;
318
- inputType?: "number" | "text" | "password" | undefined;
319
- placeholder?: string | undefined;
320
- } | {
321
- value: string;
322
- type: import("@metamask/snaps-sdk").NodeType.Button;
323
- name?: string | undefined;
324
- variant?: "primary" | "secondary" | undefined;
325
- buttonType?: "button" | "submit" | undefined;
326
- })[];
327
- } | undefined;
251
+ error: import("@metamask/snaps-sdk").Json;
252
+ };
253
+ id: string;
254
+ notifications: {
255
+ message: string;
256
+ type: "native" | "inApp";
257
+ id: string;
258
+ }[];
328
259
  }, {
329
260
  id: import("superstruct").Struct<string, null>;
330
261
  response: import("superstruct").Struct<{
@@ -345,73 +276,65 @@ export declare const SnapResponseStruct: import("superstruct").Struct<{
345
276
  message: import("superstruct").Struct<string, null>;
346
277
  type: import("superstruct").Struct<"native" | "inApp", null>;
347
278
  }>>;
348
- content: import("superstruct").Struct<import("@metamask/snaps-sdk").Panel | {
349
- value: string;
350
- type: import("@metamask/snaps-sdk").NodeType.Copyable;
351
- sensitive?: boolean | undefined;
352
- } | {
353
- type: import("@metamask/snaps-sdk").NodeType.Divider;
354
- } | {
355
- value: string;
356
- type: import("@metamask/snaps-sdk").NodeType.Heading;
357
- } | {
358
- value: string;
359
- type: import("@metamask/snaps-sdk").NodeType.Image;
360
- } | {
361
- type: import("@metamask/snaps-sdk").NodeType.Spinner;
362
- } | {
363
- value: string;
364
- type: import("@metamask/snaps-sdk").NodeType.Text;
365
- markdown?: boolean | undefined;
366
- } | {
367
- value: `0x${string}`;
368
- type: import("@metamask/snaps-sdk").NodeType.Address;
279
+ }>;
280
+ export declare const SnapResponseWithInterfaceStruct: import("superstruct").Struct<{
281
+ response: {
282
+ result: import("@metamask/snaps-sdk").Json;
369
283
  } | {
370
- value: {
371
- value: string;
372
- type: import("@metamask/snaps-sdk").NodeType.Image;
373
- } | {
374
- value: string;
375
- type: import("@metamask/snaps-sdk").NodeType.Text;
376
- markdown?: boolean | undefined;
377
- } | {
378
- value: `0x${string}`;
379
- type: import("@metamask/snaps-sdk").NodeType.Address;
380
- };
381
- type: import("@metamask/snaps-sdk").NodeType.Row;
382
- label: string;
383
- variant?: "default" | "warning" | "critical" | undefined;
284
+ error: import("@metamask/snaps-sdk").Json;
285
+ };
286
+ id: string;
287
+ getInterface: Function;
288
+ notifications: {
289
+ message: string;
290
+ type: "native" | "inApp";
291
+ id: string;
292
+ }[];
293
+ }, {
294
+ getInterface: import("superstruct").Struct<Function, null>;
295
+ response: import("superstruct").Struct<{
296
+ result: import("@metamask/snaps-sdk").Json;
384
297
  } | {
385
- type: import("@metamask/snaps-sdk").NodeType.Input;
386
- name: string;
387
- value?: string | undefined;
388
- error?: string | undefined;
389
- label?: string | undefined;
390
- inputType?: "number" | "text" | "password" | undefined;
391
- placeholder?: string | undefined;
298
+ error: import("@metamask/snaps-sdk").Json;
299
+ }, null>;
300
+ id: import("superstruct").Struct<string, null>;
301
+ notifications: import("superstruct").Struct<{
302
+ message: string;
303
+ type: "native" | "inApp";
304
+ id: string;
305
+ }[], import("superstruct").Struct<{
306
+ message: string;
307
+ type: "native" | "inApp";
308
+ id: string;
309
+ }, {
310
+ id: import("superstruct").Struct<string, null>;
311
+ message: import("superstruct").Struct<string, null>;
312
+ type: import("superstruct").Struct<"native" | "inApp", null>;
313
+ }>>;
314
+ }>;
315
+ export declare const SnapResponseStruct: import("superstruct").Struct<{
316
+ response: {
317
+ result: import("@metamask/snaps-sdk").Json;
392
318
  } | {
393
- value: string;
394
- type: import("@metamask/snaps-sdk").NodeType.Button;
395
- name?: string | undefined;
396
- variant?: "primary" | "secondary" | undefined;
397
- buttonType?: "button" | "submit" | undefined;
319
+ error: import("@metamask/snaps-sdk").Json;
320
+ };
321
+ id: string;
322
+ notifications: {
323
+ message: string;
324
+ type: "native" | "inApp";
325
+ id: string;
326
+ }[];
327
+ } | {
328
+ response: {
329
+ result: import("@metamask/snaps-sdk").Json;
398
330
  } | {
399
- type: import("@metamask/snaps-sdk").NodeType.Form;
400
- name: string;
401
- children: ({
402
- type: import("@metamask/snaps-sdk").NodeType.Input;
403
- name: string;
404
- value?: string | undefined;
405
- error?: string | undefined;
406
- label?: string | undefined;
407
- inputType?: "number" | "text" | "password" | undefined;
408
- placeholder?: string | undefined;
409
- } | {
410
- value: string;
411
- type: import("@metamask/snaps-sdk").NodeType.Button;
412
- name?: string | undefined;
413
- variant?: "primary" | "secondary" | undefined;
414
- buttonType?: "button" | "submit" | undefined;
415
- })[];
416
- } | undefined, null>;
417
- }>;
331
+ error: import("@metamask/snaps-sdk").Json;
332
+ };
333
+ id: string;
334
+ getInterface: Function;
335
+ notifications: {
336
+ message: string;
337
+ type: "native" | "inApp";
338
+ id: string;
339
+ }[];
340
+ }, null>;
@@ -1,21 +1,8 @@
1
- import type { NotificationType, EnumToUnion, Component } from '@metamask/snaps-sdk';
1
+ import type { Component, NotificationType, EnumToUnion } from '@metamask/snaps-sdk';
2
+ import type { InferMatching } from '@metamask/snaps-utils';
2
3
  import type { Json, JsonRpcId, JsonRpcParams } from '@metamask/utils';
3
4
  import type { Infer } from 'superstruct';
4
5
  import type { SignatureOptionsStruct, SnapOptionsStruct, SnapResponseStruct, TransactionOptionsStruct } from './internals';
5
- declare module 'expect' {
6
- interface AsymmetricMatchers {
7
- toRespondWith(response: unknown): void;
8
- toRespondWithError(error: unknown): void;
9
- toSendNotification(message: string, type?: EnumToUnion<NotificationType>): void;
10
- toRender(component: Component): void;
11
- }
12
- interface Matchers<R> {
13
- toRespondWith(response: unknown): R;
14
- toRespondWithError(error: unknown): R;
15
- toSendNotification(message: string, type?: EnumToUnion<NotificationType>): R;
16
- toRender(component: Component): R;
17
- }
18
- }
19
6
  export declare type RequestOptions = {
20
7
  /**
21
8
  * The JSON-RPC request ID.
@@ -78,6 +65,21 @@ export declare type SignatureOptions = Infer<typeof SignatureOptionsStruct>;
78
65
  * @property timeout - The timeout in milliseconds to use. Defaults to `1000`.
79
66
  */
80
67
  export declare type SnapOptions = Infer<typeof SnapOptionsStruct>;
68
+ export declare type SnapInterfaceActions = {
69
+ /**
70
+ * Click on an interface element.
71
+ *
72
+ * @param name - The element name to click.
73
+ */
74
+ clickElement(name: string): Promise<void>;
75
+ /**
76
+ * Type a value in a interface field.
77
+ *
78
+ * @param name - The element name to type in.
79
+ * @param value - The value to type.
80
+ */
81
+ typeInField(name: string, value: string): Promise<void>;
82
+ };
81
83
  /**
82
84
  * A `snap_dialog` alert interface.
83
85
  */
@@ -139,7 +141,7 @@ export declare type SnapPromptInterface = {
139
141
  */
140
142
  cancel(): Promise<void>;
141
143
  };
142
- export declare type SnapInterface = SnapAlertInterface | SnapConfirmationInterface | SnapPromptInterface;
144
+ export declare type SnapInterface = (SnapAlertInterface | SnapConfirmationInterface | SnapPromptInterface) & SnapInterfaceActions;
143
145
  export declare type SnapRequestObject = {
144
146
  /**
145
147
  * Get a user interface object from a snap. This will throw an error if the
@@ -200,7 +202,7 @@ export declare type Snap = {
200
202
  * will be filled in with default values.
201
203
  * @returns The response.
202
204
  */
203
- onTransaction(transaction?: Partial<TransactionOptions>): Promise<SnapResponse>;
205
+ onTransaction(transaction?: Partial<TransactionOptions>): Promise<SnapResponseWithInterface>;
204
206
  /**
205
207
  * Send a transaction to the snap.
206
208
  *
@@ -210,7 +212,7 @@ export declare type Snap = {
210
212
  * @returns The response.
211
213
  * @deprecated Use {@link onTransaction} instead.
212
214
  */
213
- sendTransaction(transaction?: Partial<TransactionOptions>): Promise<SnapResponse>;
215
+ sendTransaction(transaction?: Partial<TransactionOptions>): Promise<SnapResponseWithInterface>;
214
216
  /**
215
217
  * Send a signature request to the snap.
216
218
  *
@@ -219,7 +221,7 @@ export declare type Snap = {
219
221
  * Any missing fields will be filled in with default values.
220
222
  * @returns The response.
221
223
  */
222
- onSignature(signature?: Partial<SignatureOptions>): Promise<SnapResponse>;
224
+ onSignature(signature?: Partial<SignatureOptions>): Promise<SnapResponseWithInterface>;
223
225
  /**
224
226
  * Run a cronjob in the snap. This is similar to {@link request}, but the
225
227
  * request will be sent to the `onCronjob` method of the snap.
@@ -246,7 +248,7 @@ export declare type Snap = {
246
248
  *
247
249
  * @returns The response.
248
250
  */
249
- onHomePage(): Promise<SnapResponse>;
251
+ onHomePage(): Promise<SnapResponseWithInterface>;
250
252
  /**
251
253
  * Mock a JSON-RPC request. This will cause the snap to respond with the
252
254
  * specified response when a request with the specified method is sent.
@@ -282,4 +284,23 @@ export declare type Snap = {
282
284
  */
283
285
  close(): Promise<void>;
284
286
  };
285
- export declare type SnapResponse = Infer<typeof SnapResponseStruct>;
287
+ export declare type SnapHandlerInterface = {
288
+ content: Component;
289
+ } & SnapInterfaceActions;
290
+ export declare type SnapResponseWithInterface = {
291
+ id: string;
292
+ response: {
293
+ result: Json;
294
+ } | {
295
+ error: Json;
296
+ };
297
+ notifications: {
298
+ id: string;
299
+ message: string;
300
+ type: EnumToUnion<NotificationType>;
301
+ }[];
302
+ getInterface(): SnapHandlerInterface;
303
+ };
304
+ export declare type SnapResponseWithoutInterface = Omit<SnapResponseWithInterface, 'getInterface'>;
305
+ export declare type SnapResponseType = SnapResponseWithoutInterface | SnapResponseWithInterface;
306
+ export declare type SnapResponse = InferMatching<typeof SnapResponseStruct, SnapResponseType>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-jest",
3
- "version": "6.0.2",
3
+ "version": "7.0.0",
4
4
  "description": "A Jest preset for end-to-end testing MetaMask Snaps, including a Jest environment, and a set of Jest matchers.",
5
5
  "sideEffects": false,
6
6
  "exports": {
@@ -46,11 +46,11 @@
46
46
  "@metamask/json-rpc-middleware-stream": "^7.0.1",
47
47
  "@metamask/key-tree": "^9.0.0",
48
48
  "@metamask/permission-controller": "^9.0.2",
49
- "@metamask/snaps-controllers": "^6.0.4",
50
- "@metamask/snaps-execution-environments": "^5.0.4",
51
- "@metamask/snaps-rpc-methods": "^7.0.2",
52
- "@metamask/snaps-sdk": "^3.2.0",
53
- "@metamask/snaps-utils": "^7.0.4",
49
+ "@metamask/snaps-controllers": "^7.0.0",
50
+ "@metamask/snaps-execution-environments": "^6.0.0",
51
+ "@metamask/snaps-rpc-methods": "^8.0.0",
52
+ "@metamask/snaps-sdk": "^4.0.0",
53
+ "@metamask/snaps-utils": "^7.1.0",
54
54
  "@metamask/utils": "^8.3.0",
55
55
  "@reduxjs/toolkit": "^1.9.5",
56
56
  "express": "^4.18.2",