Skip to main content
Glama
readablepromise.test.ts1.55 kB
// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors // SPDX-License-Identifier: Apache-2.0 import { ReadablePromise } from './readablepromise'; describe('ReadablePromise', () => { test('read resolve', async () => { const readable = new ReadablePromise(Promise.resolve('x')); expect(readable.isPending()).toBe(true); expect(() => readable.read()).toThrow(); await readable; expect(readable.isPending()).toBe(false); expect(readable.read()).toBe('x'); }); test('read reject', async () => { expect.assertions(2); const promise = new ReadablePromise(Promise.reject(new Error('x'))); try { await promise; } catch (err) { expect((err as Error).message).toBe('x'); } expect(() => promise.read()).toThrow('x'); }); test('then', async () => { const onFulfilled = jest.fn(); const readable = new ReadablePromise(Promise.resolve('x')).then(onFulfilled); await readable; expect(onFulfilled).toHaveBeenCalled(); }); test('catch', async () => { const onRejected = jest.fn(); const promise = new ReadablePromise(Promise.reject(new Error('x'))).catch(onRejected); try { await promise; } catch (err) { expect((err as Error).message).toBe('x'); } expect(onRejected).toHaveBeenCalled(); }); test('finally', async () => { const onFinally = jest.fn(); const readable = new ReadablePromise(Promise.resolve('x')).finally(onFinally); await readable; expect(onFinally).toHaveBeenCalled(); }); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/medplum/medplum'

If you have feedback or need assistance with the MCP directory API, please join our Discord server