How to use code - 10 common examples

To help you get started, we’ve selected a few code 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 joyent / cloudapi-gql / test / formatters.js View on Github external
it('can change the image type property value to upper-case and replaces dashes with underscores', () => {
    const result = Formatters.Image.type({ type: 'salisbury-steak' });
    expect(result).to.equal('SALISBURY_STEAK');
  });
github joyent / cloudapi-gql / test / firewallRules.js View on Github external
it('can apply tagged rules for creating a machine', async () => {
    const fetch = TestDouble.func();
    const rule = Object.assign({}, firewallRule);
    rule.rule = 'FROM tag bacon TO tag flavor=smokey ALLOW udp port 8675';
    TestDouble.when(fetch('/fwrules')).thenResolve([rule]);
    const tags = [{ name: 'bacon' }, { name: 'flavor', value: 'smokey' }];
    const res = await FirewallRules.firewall_rules_create_machine(fetch, { tags });
    expect(res).to.exist();
    expect(res.length).to.equal(1);
    expect(res[0].rule_obj.action).to.equal('allow');
    const tag = res[0].rule_obj.from[0][1];
    expect(tag).to.equal('bacon');
  });
github aaronmccall / cvss / test / scores.js View on Github external
it('reduces 8.22 with the combined product of exploitability scores', function () {
      var simpleScores = keys.exploitability.reduce(scoreReducer, {});
      expect(scores.getExploitability(simpleScores)).to.equal(8.22 / Math.pow(2, keys.exploitability.length))

      var envScores = keys.envExploitability.reduce(scoreReducer, {});
      expect(scores.getExploitability(envScores, { env: true })).to.equal(8.22 / Math.pow(2, keys.envExploitability.length));
    });
  });
github aaronmccall / cvss / test / main.js View on Github external
it('throws if validation fails and option.throw is truthy', function () {
      expect(function () {
        main.getScore(internals.vectorString.slice(4), { throw: true });
      }).to.throw(Error, /Invalid vector string/);
    });
github tjmehta / primus-graphql / test / relay-network-layer.unit.js View on Github external
it('should subscribe to retryable observable and return rx-subscription', function () {
        this.primus.graphql.returns(this.observable)
        var rxSubscription = this.networkLayer.sendSubscription(this.subscriptionRequest)
        expect(rxSubscription).to.exist()
        expect(rxSubscription.unsubscribe).to.be.a.function()
        sinon.assert.calledOnce(this.backoffObservable.subscribe)
        sinon.assert.calledWith(this.backoffObservable.subscribe,
          expectBound(this.subscriptionRequest.onNext),
          expectName('onFinalError'),
          expectBound(this.subscriptionRequest.onCompleted))
      })
github bsiddiqui / bookshelf-bcrypt / test / spec / general.js View on Github external
lab.test('should not call extended two times', co.wrap(function * () {
    let bookshelf = require('bookshelf')(db.bookshelf.knex)
    bookshelf.plugin(require('../../'))

    let Model = bookshelf.Model.extend({
      tableName: 'users'
    })

    let error = yield Model.forge({ email: 'wont@exists' })
    .fetch({ require: true })
    .catch(err => err)

    expect(error).to.be.instanceof(bookshelf.Model.NotFoundError)
  }))
github bsiddiqui / bookshelf-paranoia / test / spec / general.js View on Github external
lab.test('should not be able to delete twice', co.wrap(function * () {
    yield Comment.forge({ id: 1 }).destroy()

    const error = yield Comment.forge({ id: 1 })
      .destroy({ require: true })
      .catch((err) => err)

    expect(error).to.be.instanceOf(Comment.NoRowsDeletedError)
  }))
github aaronmccall / cvss / test / vector.js View on Github external
it('returns an error if input is neither object nor string', function () {

      var error = vector.validate(null).error;
      expect(error).to.be.an.instanceOf(TypeError);
      expect(error.toString()).to.contain('must be an object or string');
    });
github bsiddiqui / bookshelf-paranoia / test / spec / sentinel.js View on Github external
lab.test('should error if the sentinel column does not exist', co.wrap(function * () {
    let bookshelf = yield customDb.altFieldTable((bookshelf) => {
      bookshelf.plugin(require('../../'), { sentinel: 'active' })
    })
    let Model = bookshelf.Model.extend({ tableName: 'test', softDelete: true })

    let err = yield Model.forge().save().catch((err) => err)
    expect(err).to.be.an.error(/has no column/)
  }))
github bsiddiqui / bookshelf-paranoia / test / spec / general.js View on Github external
lab.test('should throw when required', co.wrap(function * () {
      let err = yield Comment.forge({ id: 12345 })
        .destroy({ require: true })
        .catch((err) => err)

      expect(err).to.be.an.error('No Rows Deleted')
    }))

code

assertion library

BSD-3-Clause
Latest version published 6 years ago

Package Health Score

53 / 100
Full package analysis

Popular code functions