Example #1
0
      this.openTestDatabase(function (db) {

        assert.exception(
            db.approximateSize.bind(db)
          , { name: 'ReadError', message: 'approximateSize() requires start, end and callback arguments' }
          , 'no-arg approximateSize() throws'
        )

        assert.exception(
            db.approximateSize.bind(db, 'foo')
          , { name: 'ReadError', message: 'approximateSize() requires start, end and callback arguments' }
          , 'callback-less, 1-arg approximateSize() throws'
        )

        assert.exception(
            db.approximateSize.bind(db, 'foo', 'bar')
          , { name: 'ReadError', message: 'approximateSize() requires start, end and callback arguments' }
          , 'callback-less, 2-arg approximateSize() throws'
        )

        assert.exception(
            db.approximateSize.bind(db, 'foo', 'bar', {})
          , { name: 'ReadError', message: 'approximateSize() requires start, end and callback arguments' }
          , 'callback-less, 3-arg approximateSize(), no cb throws'
        )

        done()
      })
Example #2
0
 it("throws if given argument is not a string", function () {
     assert.exception(function () {
         sinonMatch.typeOf();
     }, "TypeError");
     assert.exception(function () {
         sinonMatch.typeOf(123);
     }, "TypeError");
 });
Example #3
0
 it("throws if given argument is not a function", function () {
     assert.exception(function () {
         sinonMatch.instanceOf();
     }, "TypeError");
     assert.exception(function () {
         sinonMatch.instanceOf("foo");
     }, "TypeError");
 });
Example #4
0
 it("throws if first argument is not string", function () {
     assert.exception(function () {
         matcher();
     }, "TypeError");
     assert.exception(function () {
         matcher(123);
     }, "TypeError");
 });
Example #5
0
    this.openTestDatabase(function (db) {
      assert.exception(
        db.batch.bind(db, null, {}),
        { name: 'WriteError', message: 'batch() requires an array argument' },
        'no-arg batch() throws'
      )

      assert.exception(
        db.batch.bind(db, {}),
        { name: 'WriteError', message: 'batch() requires an array argument' },
        '1-arg, no Array batch() throws'
      )

      done()
    })
 'put() with undefined key causes error': function (done) {
   assert.exception(
     this.db.put.bind(this.db, undefined, 'foo'),
     { name: 'WriteError', message: 'put() requires a key argument' }
   )
   done()
 },
 'del() with null key causes error': function (done) {
   assert.exception(
     this.db.del.bind(this.db, null),
     { name: 'WriteError', message: 'del() requires a key argument' }
   )
   done()
 },
 'get() with undefined key causes error': function (done) {
   assert.exception(
     this.db.get.bind(this.db, undefined),
     { name: 'ReadError', message: 'get() requires a key argument' }
   )
   done()
 },
Example #9
0
      this.openTestDatabase(function (db) {

        assert.exception(
            db.put.bind(db)
          , { name: 'WriteError', message: 'put() requires key and value arguments' }
          , 'no-arg put() throws'
        )

        assert.exception(
            db.put.bind(db, 'foo')
          , { name: 'WriteError', message: 'put() requires key and value arguments' }
          , 'callback-less, 1-arg put() throws'
        )

        done()
      })
Example #10
0
 this.openTestDatabase(function (db) {
   assert.exception(
     db.get.bind(db),
     { name: 'ReadError', message: 'get() requires a key argument' },
     'no-arg get() throws'
   )
   done()
 })
Example #11
0
test('#transitionTo throws an useful error when called with an abstract route', () => {
  router.map((route) => {
    route('foo', {abstract: true})
  }).listen()

  assert.exception(function () {
    router.transitionTo('foo')
  }, {message: 'No route is named foo'})
})
 'test wrong version': function () {
   var levelup = require('..')
   require('leveldown/package').version = '0.0.0'
   assert.exception(levelup.bind(null, '/foo/bar'), function (err) {
     if (err.name !== 'LevelUPError') { return false }
     if (!/Installed version of LevelDOWN \(0\.0\.0\) does not match required version \(\^\d+\.\d+\.\d+\)/.test(err.message)) { return false }
     return true
   })
 },
    this.openTestDatabase(function (db) {
      assert.exception(
        db.del.bind(db),
        { name: 'WriteError', message: 'del() requires a key argument' },
        'no-arg del() throws'
      )

      done()
    })
Example #14
0
 this.verify = function (cb) {
   assert.exception(cb, function (err) {
     if (err.name != 'WriteError')
       return false
     if ('write() already called on this batch' != err.message)
       return false
     return true
   })
 }
Example #15
0
      , 'test batch#del() with missing `key`': function () {
          // key = undefined
          assert.exception(this.batch.del.bind(this.batch, undefined, 'foo1'), function (err) {
            if (err.name != 'WriteError')
              return false
            if ('key cannot be `null` or `undefined`' != err.message)
              return false
            return true
          })

          // key = null
          assert.exception(this.batch.del.bind(this.batch, null, 'foo1'), function (err) {
            if (err.name != 'WriteError')
              return false
            if ('key cannot be `null` or `undefined`' != err.message)
              return false
            return true
          })
        }
Example #16
0
      , 'test batch#put() with missing `key` and `value`': function () {
          // undefined
          assert.exception(this.batch.put.bind(this.batch), function (err) {
            if (err.name != 'WriteError')
              return false
            if ('key cannot be `null` or `undefined`' != err.message)
              return false
            return true
          })

          // null
          assert.exception(this.batch.put.bind(this.batch, null, null), function (err) {
            if (err.name != 'WriteError')
              return false
            if ('key cannot be `null` or `undefined`' != err.message)
              return false
            return true
          })
        }
    this.openTestDatabase(function (db) {
      assert.exception(
        db.get.bind(db),
        { name: 'ReadError', message: 'get() requires key and callback arguments' },
        'no-arg get() throws'
      )

      assert.exception(
        db.get.bind(db, 'foo'),
        { name: 'ReadError', message: 'get() requires key and callback arguments' },
        'callback-less, 1-arg get() throws'
      )

      assert.exception(
        db.get.bind(db, 'foo', {}),
        { name: 'ReadError', message: 'get() requires key and callback arguments' },
        'callback-less, 2-arg get() throws'
      )

      done()
    })
function assertRequireThrows (module) {
  var levelup = require('..')
  var error = 'Wow, this is kind of evil isn\'t it?'
  // simulate an exception from a require() that doesn't resolved a package
  Object.defineProperty(require.cache, require.resolve(module), {
    get: function () {
      throw new Error(error)
    }
  })
  assert.exception(levelup.bind(null, '/foo/bar'), function (err) {
    if (err.name !== 'LevelUPError') { return false }
    var template = 'Failed to require LevelDOWN (%s). Try `npm install leveldown` if it\'s missing'
    if (format(template, error) !== err.message) { return false }
    return true
  })
}
 , 'test no leveldown': function () {
     var levelup = require('..')
     // simulate an exception from a require() that doesn't resolved a package
     Object.defineProperty(require.cache, require.resolve('leveldown'), {
       get: function() {
         throw new Error('Wow, this is kind of evil isn\'t it?')
       }
     })
     assert.exception(levelup.bind(null, '/foo/bar'), function (err) {
       if (err.name != 'LevelUPError')
         return false
       if ('Could not locate LevelDOWN, try `npm install leveldown`' != err.message)
         return false
       return true
     })
   }
Example #20
0
    it('should fail immediately on exceptions in namespaces when immediateExceptions is true',  function(){
        var func1 = function(){
                throw('some error');
            },
            spy1 = sinon.spy();

        PubSub.subscribe( 'buy', func1 );
        PubSub.subscribe( 'buy', spy1 );

        PubSub.immediateExceptions = true;

        assert.exception( function(){
            PubSub.publishSync( 'buy.tomatoes', 'some data' );
        });

        refute( spy1.called );

        // make sure we restore PubSub to it's original state
        delete PubSub.immediateExceptions;
    });
Example #21
0
    it('should fail immediately on exceptions when immediateExceptions is true', function(){
        var message = TestHelper.getUniqueString(),
            func1 = function(){
                throw('some error');
            },
            spy1 = sinon.spy(),
            spy2 = sinon.spy();


        PubSub.subscribe( message, func1 );
        PubSub.subscribe( message, spy1 );

        PubSub.immediateExceptions = true;

        assert.exception( function(){
            PubSub.publishSync( message, 'some data' );
        });

        refute( spy1.called );
        refute( spy2.called );

        // make sure we restore PubSub to it's original state
        delete PubSub.immediateExceptions;
    });
Example #22
0
    it('should call all subscribers, even if there are exceptions', function( done ){
        var message = TestHelper.getUniqueString(),
            func1 = function(){
                throw('some error');
            },
            spy1 = sinon.spy(),
            spy2 = sinon.spy(),
            clock = sinon.useFakeTimers();

        PubSub.subscribe( message, func1 );
        PubSub.subscribe( message, spy1 );
        PubSub.subscribe( message, spy2 );

        assert.exception( function(){
            PubSub.publishSync( message, 'some data' );
            clock.tick(1);
        });

        assert( spy1.called );
        assert( spy2.called );

        done();
        clock.restore();
    });
Example #23
0
 it('should require a parent', function () {
     assert.exception(function () {
         Qt.createQmlObject(qmlRectangleString);
     }, { message: 'parent' });
 });
Example #24
0
 'levelup()': function () {
   assert.isFunction(levelup)
   assert.equals(levelup.length, 3) // location, options & callback arguments
   assert.exception(levelup, 'InitializationError') // no location
 },
Example #25
0
 it("requires matcher argument", function () {
     assert.exception(function () {
         sinonMatch.instanceOf(Error).or();
     }, "TypeError");
 });
Example #26
0
 , 'test search() throws RepositorySetupError if setup() has not been called': function () {
     assert.exception(repository.search, 'RepositorySetupError')
   }