Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "mTAP3og3khORsMc/TjpVQNieT8ORJC3h01SxkDOFqLE=",
"shasum": "3ngRXZHVyqZB3sk6u9Hpj2V4SUjrhxb6D/aqesFSmeY=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
37 changes: 37 additions & 0 deletions packages/examples/packages/preinstalled/src/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,43 @@ describe('onRpcRequest', () => {
});
});
});

describe('trackError', () => {
it('tracks an error', async () => {
const { request } = await installSnap();

const response = await request({
method: 'trackError',
});

expect(response).toRespondWith(null);
expect(response).toTrackError(
expect.objectContaining({
name: 'TestError',
message: 'This is a test error.',
}),
);
});
});

describe('trackEvent', () => {
it('tracks an event', async () => {
const { request } = await installSnap();

const response = await request({
method: 'trackEvent',
});

expect(response).toRespondWith(null);
expect(response).toTrackEvent({
event: 'Test Event',
properties: {
// eslint-disable-next-line @typescript-eslint/naming-convention
test_property: 'test value',
},
});
});
});
});

describe('onSettingsPage', () => {
Expand Down
16 changes: 16 additions & 0 deletions packages/examples/packages/preinstalled/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ request }) => {
});
}

case 'trackEvent': {
return await snap.request({
method: 'snap_trackEvent',
params: {
event: {
event: 'Test Event',
properties: {
// Event properties must be snake_case.
// eslint-disable-next-line @typescript-eslint/naming-convention
test_property: 'test value',
},
},
},
});
}

case 'startTrace':
return await snap.request({
method: 'snap_startTrace',
Expand Down
2 changes: 1 addition & 1 deletion packages/snaps-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"cron-parser": "^4.5.0",
"fast-deep-equal": "^3.1.3",
"get-npm-tarball-url": "^2.0.3",
"immer": "^9.0.6",
"immer": "^9.0.21",
"luxon": "^3.5.0",
"nanoid": "^3.3.10",
"readable-stream": "^3.6.2",
Expand Down
33 changes: 33 additions & 0 deletions packages/snaps-jest/src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,39 @@ interface SnapsMatchers {
* expect(ui).toRender(panel([heading('Hello, world!')]));
*/
toRender(component: ComponentOrElement): void;

/**
* Assert that the Snap tracked an error with the expected parameters. This
* is equivalent to calling
* `expect(response.tracked.errors).toContainEqual(error)`.
*
* @param error - The expected error parameters.
* @throws If the snap did not track an error with the expected parameters.
* @example
* const response = await request({ method: 'foo' });
* expect(response).toTrackError({
* name: 'Error',
* message: 'This is an error.',
* });
*/
toTrackError(error?: unknown): void;

/**
* Assert that the Snap tracked an event with the expected parameters. This
* is equivalent to calling
* `expect(response.tracked.events).toContainEqual(event)`.
*
* @param event - The expected event parameters.
* @throws If the snap did not track an event with the expected parameters.
* @example
* const response = await request({ method: 'foo' });
* expect(response).toTrackEvent({
* event: 'bar',
* properties: { baz: 'qux' },
* sensitiveProperties: { quux: 'corge' },
* });
*/
toTrackEvent(event?: unknown): void;
}

// Extend the `expect` interface with the new matchers. This is used when
Expand Down
Loading
Loading