test('session unknown message', function (t) { t.plan(2) const session = new BrowserSession('abc', 30e3, '.') session.on('error', function (err) { t.is(err.message, 'Unknown message type') }) session.on('close', function () { t.pass('closed') }) session.resume() session.write({ type: 'foo' }) })
export function unregister() { if ('serviceWorker' in navigator) { navigator.serviceWorker.ready .then(registration => { registration.unregister(); }) .catch(error => { console.error(error.message); }); } }
_remove(user) { if (this.partial) return; this.users.cache.delete(user.id); if (!this.me || user.id !== this.message.client.user.id) this.count--; if (user.id === this.message.client.user.id) this.me = false; if (this.count <= 0 && this.users.cache.size === 0) { this.message.reactions.cache.delete(this.emoji.id || this.emoji.name); } }
/** * Handles checking if the message has been deleted, and if so, stops the collector with the reason 'messageDelete'. * @private * @param {Message} message The message that was deleted * @returns {void} */ _handleMessageDeletion(message) { if (message.id === this.message.id) { this.stop('messageDelete'); } }
constructor(reaction, emoji) { super(reaction.message.client, emoji); /** * The message reaction this emoji refers to * @type {MessageReaction} */ this.reaction = reaction; }
suggest(input = this.input, choices = this.state._choices) { if (typeof this.options.suggest === 'function') { return this.options.suggest.call(this, input, choices); } let str = input.toLowerCase(); return choices.filter(ch => ch.message.toLowerCase().includes(str)); }
which(command) { return new Promise(resolve => which(command, (error, resolvedPath) => resolve({ resolvedPath: resolvedPath, error: error ? error.message : null }))); }
it("should return an error when pusage fails", (done) => { sandbox.stub(pusage, "stat").yields(new Error("bad error")); agent._getStats((err, metrics) => { tryCatch(done, () => { expect(err).to.exist; expect(metrics).to.be.undefined; expect(err.message).to.equal("bad error"); }); }); });
/** * Render the scale "Key". Something like: * @return {String} */ renderScaleKey() { if (this.scaleKey === false) return ''; if (this.state.submitted) return ''; let scale = this.scale.map(item => ` ${item.name} - ${item.message}`); let key = ['', ...scale].map(item => this.styles.muted(item)); return key.join('\n'); }
/** * @api {get} /api/v1/message get * @apiName get * @apiGroup Message * */ async function get(req, res) { const messages = await gladys.message.get(req.user.id); res.json(messages); }
isEven(value) { const result = triggersSchema.validate(value); if (result.error) { throw new Error(result.error.details[0].message); } }
heading(prompt, choice) { choice.disabled = ''; choice.indicator = [choice.indicator, ' '].find(v => v != null); choice.message = choice.message || ''; return choice; }
test('handleRequest function - invoke with error', t => { t.plan(1) const request = {} const reply = {} reply.send = (err) => t.is(err.message, 'Kaboom') handleRequest(new Error('Kaboom'), request, reply) })
test('Fastify should throw on wrong options', t => { t.plan(2) try { Fastify('lol') t.fail() } catch (e) { t.is(e.message, 'Options must be an object') t.pass() } })