How to use @hapi/lab - 10 common examples

To help you get started, we’ve selected a few @hapi/lab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github academia-de-codigo / noire-server / test / utils / manager.js View on Github external
const Lab = require('@hapi/lab');
const Exiting = require('exiting');
const Manager = require('utils/manager');
const Config = require('config');
const ConfigValidation = require('utils/config-validation');
const Sinon = require('sinon');

const { after, before, beforeEach, describe, expect, it } = (exports.lab = Lab.script());

describe('Manager', () => {
    before(() => {
        // Silence log messages
        Exiting.log = function() {};
    });

    beforeEach(() => {
        Manager.reset();
    });

    after(() => {
        Manager.reset();
    });

    it('validates configuration', async flags => {
github hapijs / topo / test / index.ts View on Github external
import * as Topo from '..';
import * as Lab from '@hapi/lab';


const { expect } = Lab.types;


// new Topo.Sorter()

const morning = new Topo.Sorter();
morning.add('Nap', { after: ['breakfast', 'prep'] })
morning.add(['Make toast', 'Pour juice'], { before: 'breakfast', group: 'prep' });
morning.add('Eat breakfast', { group: 'breakfast' });

const afternoon = new Topo.Sorter();
afternoon.add('Eat lunch', { after: ['afternoon', 'prep'], sort: 2 });

expect.type(new Topo.Sorter());


// sorter.add()
github hapijs / address / test / index.ts View on Github external
import * as Address from '..';
import * as Lab from '@hapi/lab';


const { expect } = Lab.types;


// errors

expect.type(Address.errors.FORBIDDEN_UNICODE);


// domain.analyze()

Address.domain.analyze('example.com');
Address.domain.analyze('example.com', { minDomainSegments: 3, allowUnicode: false });
Address.domain.analyze('example.com', { tlds: false });
Address.domain.analyze('example.com', { tlds: true });
Address.domain.analyze('example.com', { tlds: { allow: new Set('x') } });
Address.domain.analyze('example.com', { tlds: { allow: new Set('x') } });
Address.domain.analyze('example.com', { tlds: { allow: true } });
github hapijs / boom / test / index.ts View on Github external
import * as Boom from '..';
import * as Lab from '@hapi/lab';

const { expect } = Lab.types;


class X {

    x: number;

    constructor(value: number) {

        this.x = value;
    }
};

const decorate = new X(1);


// new Boom.Boom()
github hapijs / teamwork / test / index.ts View on Github external
import * as Lab from '@hapi/lab';
import * as Teamwork from '..';


const { expect } = Lab.types;


// Constructor tests

expect.type(new Teamwork.Team());
expect.type(new Teamwork.Team({ meetings: 2 }));
expect.error(new Teamwork.Team({ foo: true }));
expect.error(new Teamwork.Team({ meetings: 'foo' }));
expect.type>(new Teamwork.Team().work);


// Attend tests

expect.type(new Teamwork.Team().attend());
expect.type(new Teamwork.Team().attend(new Error()));
expect.type(new Teamwork.Team().attend('foo'));
github hapijs / wreck / test / index.ts View on Github external
import * as Http from 'http';
import * as Net from 'net';

import * as Code from '@hapi/code';
import * as Lab from '@hapi/lab';
import * as Wreck from '..';


const { expect } = Lab.types;


// Provision server

const server = Http.createServer((req, res) => {

    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('Some payload');
});

await new Promise((resolve) => server.listen(0, resolve));
const address = server.address() as Net.AddressInfo;
const url = `http://localhost:${address.port}`;


// request()
github hapijs / hoek / test / index.ts View on Github external
import * as Hoek from '..';
import * as Lab from '@hapi/lab';


const { expect } = Lab.types;


interface Foo {
    a?: number;
    b?: string;
};

interface Bar {
    b?: string;
    c?: boolean;
};


// deepEqual()

Hoek.deepEqual('some', 'some');
github hapijs / cryptiles / test / index.ts View on Github external
import * as Cryptiles from '..';
import * as Lab from '@hapi/lab';


const { expect } = Lab.types;


// randomString()

Cryptiles.randomString(256);
Cryptiles.randomString(5 * 5);

expect.type(Cryptiles.randomString(128))

expect.error(Cryptiles.randomString('some'));
expect.error(Cryptiles.randomString(true));
expect.error(Cryptiles.randomString({ foo: true }));
expect.error(Cryptiles.randomString(128, 256));


// randomDigits()
github hapijs / bell / test / providers / google.js View on Github external
'use strict';

const Bell = require('../..');
const Code = require('@hapi/code');
const Hapi = require('@hapi/hapi');
const Hoek = require('@hapi/hoek');
const Lab = require('@hapi/lab');

const Mock = require('../mock');


const internals = {};


const { describe, it } = exports.lab = Lab.script();
const expect = Code.expect;


describe('google', () => {

    it('authenticates with mock', async (flags) => {

        const mock = await Mock.v2(flags);
        const server = Hapi.server({ host: 'localhost', port: 80 });
        await server.register(Bell);

        const custom = Bell.providers.google();
        Hoek.merge(custom, mock.provider);

        const profile = {
            sub: '1234567890',
github hapijs / code / test / index.js View on Github external
'use strict';


const Util = require('util');

const Hoek = require('@hapi/hoek');
const Lab = require('@hapi/lab');
const Code = require('..');


const internals = {};


const { describe, it } = exports.lab = Lab.script();


describe('count()', () => {

    it('returns assertion count', () => {

        Code.expect(10).to.be.above(5);
        Code.expect('abc').to.be.a.string();
        Hoek.assert(Code.count() === 2);
    });
});

describe('expect()', () => {

    it('validates assertion', () => {

@hapi/lab

Test utility

BSD-3-Clause
Latest version published 30 days ago

Package Health Score

90 / 100
Full package analysis

Popular @hapi/lab functions