CoolFace
Apppublic

strong-tie/inbound-calls

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
expose.test.js81 linesDownload Raw Back to test
1'use strict'2 3const { test } = require('tap')4const boot = require('..')5const { AVV_ERR_EXPOSE_ALREADY_DEFINED, AVV_ERR_ATTRIBUTE_ALREADY_DEFINED } = require('../lib/errors')6const { kAvvio } = require('../lib/symbols')7 8for (const key of ['use', 'after', 'ready', 'onClose', 'close']) {9  test('throws if ' + key + ' is by default already there', (t) => {10    t.plan(1)11 12    const app = {}13    app[key] = () => { }14 15    t.throws(() => boot(app), new AVV_ERR_EXPOSE_ALREADY_DEFINED(key, key))16  })17 18  test('throws if ' + key + ' is already there', (t) => {19    t.plan(1)20 21    const app = {}22    app['cust' + key] = () => { }23 24    t.throws(() => boot(app, { expose: { [key]: 'cust' + key } }), new AVV_ERR_EXPOSE_ALREADY_DEFINED('cust' + key, key))25  })26 27  test('support expose for ' + key, (t) => {28    const app = {}29    app[key] = () => { }30 31    const expose = {}32    expose[key] = 'muahah'33 34    boot(app, {35      expose36    })37 38    t.end()39  })40}41 42test('set the kAvvio to true on the server', (t) => {43  t.plan(1)44 45  const server = {}46  boot(server)47 48  t.ok(server[kAvvio])49})50 51test('.then()', t => {52  t.plan(3)53 54  t.test('.then() can not be overwritten', (t) => {55    t.plan(1)56 57    const server = {58      then: () => {}59    }60    t.throws(() => boot(server), AVV_ERR_ATTRIBUTE_ALREADY_DEFINED('then'))61  })62 63  t.test('.then() is a function', (t) => {64    t.plan(1)65 66    const server = {}67    boot(server)68 69    t.type(server.then, 'function')70  })71 72  t.test('.then() can not be overwritten', (t) => {73    t.plan(1)74 75    const server = {}76    boot(server)77 78    t.throws(() => { server.then = 'invalid' }, TypeError('Cannot set property then of #<Object> which has only a getter'))79  })80})81