Skip to main content
Glama
execute-with-thenable.test.js1.74 kB
'use strict' const { test } = require('tap') const { executeWithThenable } = require('../../lib/execute-with-thenable') const { kAvvio } = require('../../lib/symbols') test('executeWithThenable', (t) => { t.plan(6) t.test('passes the arguments to the function', (t) => { t.plan(5) executeWithThenable((...args) => { t.equal(args.length, 3) t.equal(args[0], 1) t.equal(args[1], 2) t.equal(args[2], 3) }, [1, 2, 3], (err) => { t.error(err) }) }) t.test('function references this to itself', (t) => { t.plan(2) const func = function () { t.equal(this, func) } executeWithThenable(func, [], (err) => { t.error(err) }) }) t.test('handle resolving Promise of func', (t) => { t.plan(1) const fn = function () { return Promise.resolve(42) } executeWithThenable(fn, [], (err) => { t.error(err) }) }) t.test('handle rejecting Promise of func', (t) => { t.plan(1) const fn = function () { return Promise.reject(new Error('Arbitrary Error')) } executeWithThenable(fn, [], (err) => { t.equal(err.message, 'Arbitrary Error') }) }) t.test('dont handle avvio mocks PromiseLike results but use callback if provided', (t) => { t.plan(1) const fn = function () { const result = Promise.resolve(42) result[kAvvio] = true } executeWithThenable(fn, [], (err) => { t.error(err) }) }) t.test('dont handle avvio mocks Promises and if no callback is provided', (t) => { t.plan(1) const fn = function () { t.pass(1) const result = Promise.resolve(42) result[kAvvio] = true } executeWithThenable(fn, []) }) })

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/krtw00/search-mcp'

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