How to use the tap.throws function in tap

To help you get started, we’ve selected a few tap 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 isaacs / minizlib / test / params.js View on Github external
do {} while (deflater.read())

// twice should be no-op
deflater.params(0, zlib.constants.Z_DEFAULT_STRATEGY)
deflater.params(0, zlib.constants.Z_DEFAULT_STRATEGY)

do {} while (deflater.read())
deflater.write(chunk2)
const bufs = [];
for (let buf; buf = deflater.read(); bufs.push(buf));
actual = Buffer.concat(bufs);

t.same(actual, expected)

t.throws('invalid level', _ => deflater.params(Infinity))
t.throws('invalid strategy', _ => deflater.params(0, 'nope'))
deflater.end()
deflater.read()
deflater.close()
deflater.close()
deflater.close()

t.throws('params after end', _ => deflater.params(0, 0),
         new Error('cannot switch params when binding is closed'))
github submarineswaps / swaps-service / test / swaps / test_swap_address.js View on Github external
refund_public_key_hash: fixtures.refund_public_key_hash,
    timeout_block_height: fixtures.timeout_block_height,
  });

  equal(details.p2sh_address, '2N71ZcQEpPbyamsQXX4VKT7VbziB25zrro7');
  equal(details.p2sh_output_script, 'a91496fc515680d892a4910c16a919e083f268c4fc6587');
  equal(details.p2sh_p2wsh_output_script, 'a914c1c7d40364affdf37f5cd8924ebd67f1a0f238c687');
  equal(details.p2sh_p2wsh_address, '2NAuqncUDHErNcA9Umu7U1bdhCRjt3bkP8u');
  equal(details.p2wsh_address, 'tb1qkcavdkmfj7z8ekrnxerxpq5wrr8e66yhr0rsktalrdvtgy8n0czqsad2sm');
  equal(details.redeem_script, '76a914e2ac8cb97af3d59b1c057db4b0c4f9aa12a912738763752103f8109578aae1e5cfc497e466cf6ae6625497cd31886e87b2f4f54f3f0f46b539670354df07b17576a91410fd1a974109be99bdf95334f8b7625bda0e90be8868ac');
  equal(details.witness_output_script, '0020b63ac6db6997847cd873364660828e18cf9d68971bc70b2fbf1b58b410f37e04');
}

// No refund key should throw an error
{
  throws(() => {
    return swapAddress({
      destination_public_key: fixtures.destination_public_key,
      network: fixtures.network,
      payment_hash: fixtures.payment_hash,
      timeout_block_height: fixtures.timeout_block_height,
    });
  },
  new Error('ExpectedRefundKey'));
}
github isaacs / yallist / test / basic.js View on Github external
t.equal(Yallist().shift(), undefined)

var x = Yallist()
x.unshift(1)
t.equal(x.length, 1)
t.similar(x.toArray(), [1])

// verify that y.toArray() returns an array and if we create a
// new Yallist from that array, we get a list matching it
t.similar(Yallist(y.toArray()), y)
t.similar(Yallist.apply(null, y.toArray()), y)

t.throws(function () {
  new Yallist().reduce(function () {})
}, {}, new TypeError('Reduce of empty list with no initial value'))
t.throws(function () {
  new Yallist().reduceReverse(function () {})
}, {}, new TypeError('Reduce of empty list with no initial value'))

z = y.reverse()
t.equal(z, y)
t.similar(y.toArray(), expectReverse)
y.reverse()
t.similar(y.toArray(), expect)

var a = Yallist(1, 2, 3, 4, 5, 6)
var cases = [
  [ [2, 4], [3, 4] ],
  [ [2, -4], [] ],
  [ [2, -2], [3, 4] ],
  [ [1, -2], [2, 3, 4] ],
  [ [-1, -2], [] ],
github isaacs / yallist / test / basic.js View on Github external
e = Yallist()
e.pushNode(Yallist.Node(1))
t.same(e.toArray(), [1])

// steal them back, don't break the lists
swiped.unshiftNode(inserter.head)
t.same(swiped, Yallist(8, 99, 9, 7, 66))
t.same(inserter, Yallist(2, 3, 5, 4, 1, 8))
swiped.unshiftNode(inserter.tail)
t.same(inserter, Yallist(2, 3, 5, 4, 1))
t.same(swiped, Yallist(8, 8, 99, 9, 7, 66))

t.throws(function remove_foreign_node () {
  e.removeNode(swiped.head)
}, {}, new Error('removing node which does not belong to this list'))
t.throws(function remove_unlisted_node () {
  e.removeNode(Yallist.Node('nope'))
}, {}, new Error('removing node which does not belong to this list'))

e = Yallist(1, 2)
e.removeNode(e.head)
t.same(e, Yallist(2))
e = Yallist(1, 2)
e.removeNode(e.tail)
t.same(e, Yallist(1))

// shift all the way down
e = Yallist()
e.push(1)
e.push(2)
e.push(3)
t.equal(e.shift(), 1)
github nickkolok / paraquire / tests / requiring-json / main.js View on Github external
var paraquire = require("paraquire")(module);

const tap = require('tap');

tap.throws(
	()=>{
		var f = paraquire("./lib-requiring-json.js",{requiringJSON:false});
		console.log(f());
	},
	'Able to require forbidden JSON'
);



accessed = false;
try{
    f = paraquire("./lib-requiring-json.js",{sandbox:{process:{argv:process.argv,env:{LC_ALL:0}}}});
    if(f()!=="truefolder"){
        throw f();
    }
    accessed = true;
github npm / arborist / test / metadata.js View on Github external
package: require(fixture + '/node_modules/ghshort/package.json'),
      }), 'get from gh shorthand package.json')
      t.matchSnapshot(m.get({
        package: require(fixture + '/node_modules/full-git-url/package.json'),
      }), 'get from gh shorthand package.json')

      t.matchSnapshot(m.get({
        package: {nothing: 'here'},
      }), 'package with no metas')

      t.matchSnapshot(m.get({ location: 'package/not/found' }), 'not found pkg')
      t.end()
    })
  }))

t.throws(() =>
  new Metadata().get(), Error('attemping to read metadata before loading'))

t.test('memoize and dememoize', t => {
  const n = {
    location: '/asdf',
    integrity: 'integral',
    resolved: 'resolute',
  }
  const m = new Metadata()
  m.data = { arblock: {packages:{}}, lockfile: null }
  m.memo(n)
  t.matchSnapshot(m.data.arblock, 'memoized node')
  m.dememo(n)
  t.matchSnapshot(m.data.arblock, 'dememoized node')

  const empty = { location: '/whatever' }
github npm / node-tar / test / write-entry.js View on Github external
})

  t.test('preservePaths=false strict=true', t => {
    t.throws(_ => {
      new WriteEntry(f, {
        strict: true,
        cwd: files
      })
    }, { message: /stripping .* from absolute path/, path: f })
    t.end()
  })

  t.end()
})

t.throws(_ => new WriteEntry(null), new TypeError('path is required'))

t.test('no user environ, sets uname to empty string', t => {
  delete process.env.USER
  const ws = new WriteEntry('512-bytes.txt', { cwd: files })
  let out = []
  ws.on('data', c => out.push(c))
  ws.on('end', _ => {
    out = Buffer.concat(out)
    t.equal(out.length, 1024)
    t.match(ws.header, {
      cksumValid: true,
      needPax: false,
      path: '512-bytes.txt',
      mode: 0o644,
      size: 512,
      uname: '',
github npm / arborist / test / edge.js View on Github external
})
t.matchSnapshot(moving, 'clobbered and detached')

t.throws(() => new Edge({
  from: top,
  type: 'not a valid type',
  name: 'yoinks',
}), new TypeError('invalid type: not a valid type\n(valid types are: '))

t.throws(() => new Edge({
  type: 'prod',
  spec: '*',
  from: top,
}), new TypeError('must provide dependency name'))

t.throws(() => new Edge({
  type: 'prod',
  name: 'foo',
  spec: '',
}), new TypeError('must provide "from" node'))
github YahooArchive / mendel / test / tree-walker.js View on Github external
var shallowModule = {
    id: 'root',
    index: 0,
    data: [{
        id: 'stubData',
        sha: '010203',
    }],
};

t.equals(walker.find(shallowModule).id, 'stubData',
    'Shallow module won\'t call _resolveBranch');

t.equals(walker.find({index:0}).id, 'stubData',
    'Caches result by index');

t.throws(function() {
    walker.find({index:1, data:[1,2]});
},
'Throws if _resolveBranch not implemented by subclass');

var branchModule = {
    id: 'leaf1',
    index: 2,
    data: [{
        id: 'firstItem',
        sha: '0506FF',
    },{
        id: 'secondItem',
        sha: '0506FF',
    },{
        id: 'thirdItem',
        sha: 'bb06FF',
github submarineswaps / swaps-service / test / swaps / test_check_invoice_payable.js View on Github external
Object.keys(tests).map(k => tests[k]).forEach(test => {
  if (!test.expected_error) {
    return doesNotThrow(() => checkInvoicePayable(test.args));
  }

  throws(() => checkInvoicePayable(test.args), new Error(test.expected_error));

  return;
});