How to use bocha - 10 common examples

To help you get started, we’ve selected a few bocha 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 arnesten / smartdb / test / simple-crud.tests.js View on Github external
let bocha = require('bocha');
let sinon = require('sinon');
let testCase = bocha.testCase;
let assert = bocha.assert;
let nock = require('nock');

module.exports = testCase('simple-crud', {
    setUp() {
        this.nock = nock('http://myserver.com');
    },
    tearDown() {
        nock.cleanAll();
    },
    'get: entity that exists': async function () {
        this.nock
            .get('/main/F1').reply(200, {
            _id: 'F1',
            _rev: '1-2',
            type: 'fish'
        });
github arnesten / smartdb / test / generate-id.js.tests.js View on Github external
let bocha = require('bocha');
let testCase = bocha.testCase;
let assert = bocha.assert;
let nock = require('nock');
let SmartDb = require('../lib/SmartDb.js');

module.exports = testCase('generate-id', {
    setUp() {
        this.nock = nock('http://myserver.com');
    },
    tearDown() {
        nock.cleanAll();
    },
    'can generate ID on save': async function () {
        this.nock.put('/main/S1A', { name: 'Shark', type: 'fish' }).reply(200, {
            id: 'S1A',
            rev: 'S1B'
        });
        let db = createDb({
github arnesten / smartdb / test / event-hooks.tests.js View on Github external
let bocha = require('bocha');
let sinon = require('sinon');
let testCase = bocha.testCase;
let assert = bocha.assert;
let refute = bocha.refute;
let nock = require('nock');

module.exports = testCase('event-hooks', {
    setUp() {
        this.nock = nock('http://myserver.com');
    },
    tearDown() {
        nock.cleanAll();
    },
    'preInsert: can manipulate doc before merge': function (done) {
        this.nock
            .get('/main/F1').reply(200, {
                _id: 'F1',
                _rev: 'F1R',
                type: 'fish'
github arnesten / smartdb / test / cache-provider.tests.js View on Github external
let bocha = require('bocha');
let sinon = require('sinon');
let testCase = bocha.testCase;
let assert = bocha.assert;
let refute = bocha.refute;
let nock = require('nock');

module.exports = testCase('cache-provider', {
    setUp() {
        this.nock = nock('http://myserver.com');
    },
    tearDown() {
        nock.cleanAll();
    },
    'can use provider to get cached item': async function () {
        let db = createDb({
            databases: [
                {
                    url: 'http://myserver.com/animals',
                    entities: {
github arnesten / smartdb / test / auth.tests.js View on Github external
let bocha = require('bocha');
let testCase = bocha.testCase;
let assert = bocha.assert;
let nock = require('nock');

module.exports = testCase('auth', {
    setUp() {
        this.nock = nock('http://myserver.com');
    },
    tearDown() {
        nock.cleanAll();
    },
    'get: when giving auth and error appears, should NOT show authentication info': async function () {
        this.nock
            .get('/animals/F1').reply(500);
        let db = createDb({
            databases: [
                {
                    url: 'http://admin:12345@myserver.com/animals',
github arnesten / smartdb / test / cache.tests.js View on Github external
let bocha = require('bocha');
let sinon = require('sinon');
let testCase = bocha.testCase;
let assert = bocha.assert;
let nock = require('nock');
let SmartDb = require('../lib/SmartDb.js');

module.exports = testCase('cache', {
    setUp() {
        this.nock = nock('http://myserver.com');
    },
    tearDown() {
        nock.cleanAll();
    },
    'getting entity twice with cacheMaxSize set, should get from cache': async function () {
        this.nock
            .get('/animals/F1').reply(200, { _id: 'F1', _rev: 'F1R1', type: 'fish' })
            .get('/animals/F1').reply(200, { _id: 'F1', _rev: 'F1R2', type: 'fish' });
        let db = createDb({
            databases: [
github arnesten / smartdb / test / views.tests.js View on Github external
let bocha = require('bocha');
let testCase = bocha.testCase;
let assert = bocha.assert;
let nock = require('nock');

module.exports = testCase('views', {
    setUp() {
        this.nock = nock('http://myserver.com');
    },
    tearDown() {
        nock.cleanAll();
    },
    'view: without specified rewrite': async function () {
        this.nock
            .get('/animals/_design/fish/_view/getSharks?include_docs=true').reply(200, {
            rows: [
                { doc: { _id: 'F1', name: 'Great white' } }
            ]
        });
github arnesten / smartdb / test / fake.tests.js View on Github external
let bocha = require('bocha');
let sinon = require('sinon');
let testCase = bocha.testCase;
let assert = bocha.assert;
let refute = bocha.refute;
let smartdb = require('../lib/smartdb.js');

module.exports = testCase('fake', {
    'can fake get()': async function () {
        let fakeDb = createFake({
            entities: [
                { _id: 'F1', type: 'fish', name: 'Shark' }
            ]
        });

        let doc = await fakeDb.get('fish', 'F1');

        assert.equals(doc, { _id: 'F1', type: 'fish', name: 'Shark' });
    },
    'updateWithRetry() can update entity': async function () {
github arnesten / smartdb / test / list.tests.js View on Github external
let bocha = require('bocha');
let testCase = bocha.testCase;
let assert = bocha.assert;
let refute = bocha.refute;
let nock = require('nock');

module.exports = testCase('views', {
    setUp() {
        this.nock = nock('http://myserver.com');
    },
    tearDown() {
        nock.cleanAll();
    },
    'list: without rewrite': async function () {
        this.nock
            .get('/animals/_design/fish/_list/myList/myView?group=true').reply(200, '<b>Shark</b>');
        let db = createDb({
            databases: [
                {
github arnesten / smartdb / test / bulk.tests.js View on Github external
let bocha = require('bocha');
let testCase = bocha.testCase;
let assert = bocha.assert;
let nock = require('nock');

module.exports = testCase('auth', {
    setUp() {
        this.nock = nock('http://myserver.com');
    },
    tearDown() {
        nock.cleanAll();
    },
    'getBulk': {
        'two entities that exist': async function () {
            this.nock
                .post('/main/_all_docs', { keys: ['F1', 'F2'] })
                .query({ include_docs: 'true' })
                .reply(200, {
                    rows: [

bocha

Bringing the best of Buster.js to Mocha

MIT
Latest version published 19 days ago

Package Health Score

57 / 100
Full package analysis