Skip to content

Commit d58241e

Browse files
committed
test: add test case for type narrowing
1 parent a4c4cde commit d58241e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

packages/keyring-controller/src/KeyringController.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3156,6 +3156,26 @@ describe('KeyringController', () => {
31563156
expect(result).toBe('foo');
31573157
});
31583158
});
3159+
3160+
it('should narrow the return type based on the handler return type', async () => {
3161+
const messenger = buildKeyringControllerMessenger<
3162+
| KeyringControllerActions
3163+
| KeyringControllerWithKeyringAction<MockKeyring, string>
3164+
| KeyringControllerWithKeyringAction<MockKeyring, number>
3165+
>();
3166+
await withController({ messenger }, async ({ controller }) => {
3167+
const selector = { type: MockKeyring.type };
3168+
jest.spyOn(controller, 'withKeyring').mockResolvedValue('foo');
3169+
3170+
const result: number = await messenger.call(
3171+
'KeyringController:withKeyring',
3172+
selector,
3173+
async (_keyring: EthKeyring<Json>) => 10,
3174+
);
3175+
3176+
expect(result).toBe(10);
3177+
});
3178+
});
31593179
});
31603180

31613181
describe('prepareUserOperation', () => {

0 commit comments

Comments
 (0)