How to use the assert.throws function in assert

To help you get started, we’ve selected a few assert 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 apigee / trireme / node10 / node10tests / noderunner / test-crypto-binary-default.js View on Github external
testCipher1('MySecretKey123');
testCipher1(new Buffer('MySecretKey123'));

testCipher2('0123456789abcdef');
testCipher2(new Buffer('0123456789abcdef'));

testCipher3('0123456789abcd0123456789', '12345678');
testCipher3('0123456789abcd0123456789', new Buffer('12345678'));
testCipher3(new Buffer('0123456789abcd0123456789'), '12345678');
testCipher3(new Buffer('0123456789abcd0123456789'), new Buffer('12345678'));

testCipher4(new Buffer('0123456789abcd0123456789'), new Buffer('12345678'));


// update() should only take buffers / strings
assert.throws(function() {
  crypto.createHash('sha1').update({foo: 'bar'});
}, /uffer/);


// Test Diffie-Hellman with two parties sharing a secret,
// using various encodings as we go along
var dh1 = crypto.createDiffieHellman(256);
var p1 = dh1.getPrime('buffer');
var dh2 = crypto.createDiffieHellman(p1, 'base64');
var key1 = dh1.generateKeys();
var key2 = dh2.generateKeys('hex');
var secret1 = dh1.computeSecret(key2, 'hex', 'base64');
var secret2 = dh2.computeSecret(key1, 'binary', 'buffer');

assert.equal(secret1, secret2.toString('base64'));
github graalvm / graaljs / test / parallel / test-performance-function.js View on Github external
assert.strictEqual(typeof entry.startTime, 'number');
    obs.disconnect();
  }));
  obs.observe({ entryTypes: ['function'] });
  n();
}

{
  // If the error throws, the error should just be bubbled up and the
  // performance timeline entry will not be reported.
  const obs = new PerformanceObserver(common.mustNotCall());
  obs.observe({ entryTypes: ['function'] });
  const n = performance.timerify(() => {
    throw new Error('test');
  });
  assert.throws(() => n(), /^Error: test$/);
  obs.disconnect();
}

{
  class N {}
  const n = performance.timerify(N);

  const obs = new PerformanceObserver(common.mustCall((list) => {
    const entries = list.getEntries();
    const entry = entries[0];
    assert.strictEqual(entry[0], 1);
    assert.strictEqual(entry[1], 'abc');
    assert(entry);
    assert.strictEqual(entry.name, 'N');
    assert.strictEqual(entry.entryType, 'function');
    assert.strictEqual(typeof entry.duration, 'number');
github MobileChromeApps / mobile-chrome-apps / node_modules / cordova / node_modules / npm / node_modules / request / node_modules / http-signature / node_modules / ctype / tst / ctio / uint / tst.64.js View on Github external
}, Error, 'buffer too small');

	/* Beyond the end of the buffer */
	buf = new Buffer(12);
	data = [ 0, 0];
	ASSERT.throws(function () {
	    mod_ctype.wuint64(data, 'little', buf, 11);
	}, Error, 'write beyond end of buffer');
	ASSERT.throws(function () {
	    mod_ctype.wuint64(data, 'big', buf, 11);
	}, Error, 'write beyond end of buffer');

	/* Write negative values */
	buf = new Buffer(12);
	data = [ -3, 0 ];
	ASSERT.throws(function () {
	    mod_ctype.wuint64(data, 'big', buf, 1);
	}, Error, 'write negative number');
	ASSERT.throws(function () {
	    mod_ctype.wuint64(data, 'little', buf, 1);
	}, Error, 'write negative number');

	data = [ 0, -3 ];
	ASSERT.throws(function () {
	    mod_ctype.wuint64(data, 'big', buf, 1);
	}, Error, 'write negative number');
	ASSERT.throws(function () {
	    mod_ctype.wuint64(data, 'little', buf, 1);
	}, Error, 'write negative number');

	data = [ -3, -3 ];
	ASSERT.throws(function () {
github emmetio / abbreviation / test / element.js View on Github external
it('self-closing', () => {
		assert.equal(parse('div/'), '<div>');
		assert.equal(parse('.foo/'), '');
		assert.equal(parse('.foo[bar]/'), '');
		assert.equal(parse('.foo/*3'), '');
		assert.equal(parse('.foo*3/'), '');

		assert.throws(() =&gt; parse('/'), /Unexpected self\-closing indicator/);
	});
</div>
github pbiswas101 / Mathball / test / find-spec.js View on Github external
it('should throw an error when when factorial is passed as arg & negative number is passed as arg for factorial', () => {
		assert.throws(() => find('factorial')(-20), TypeError);
	});
github yeoman / grunt-usemin / test / test-fileprocessor.js View on Github external
it('should fail if pattern is not an array', function () {
      assert.throws(function () {
        new FileProcessor('html', {});
      }, /Patterns must be an array/);
    });
github KoteiIto / node-athena / test / client.js View on Github external
it('should return error when bucketUri is empty', function () {
            let mockReqest = getMockRequest()
            let client = Client.create(mockReqest, config)
            let newConfig = Object.assign({}, config)
            newConfig.bucketUri = ""
            assert.throws(() => { client.setConfig(newConfig) }, Error, 'buket uri required')
        })
    })
github googleapis / google-cloud-node / test / datastore / dataset.js View on Github external
it('should throw if a datasetId can not be found', function() {
      assert.throws(function() {
        new Dataset();
      }, 'A project or dataset ID is required to use a Dataset.');
    });
github calzoneman / sync / test / custom-media.js View on Github external
it('rejects empty source list', () => {
            invalid.sources = [];

            assert.throws(() => validate(invalid), /source list must be nonempty/);
        });
github JoshKaufman / ursa / test / native.js View on Github external
rsa.setPublicKeyPem(fixture.PUBLIC_KEY);

    function f2() {
        rsa.publicEncrypt("x", ursaNative.RSA_PKCS1_OAEP_PADDING);
    }
    assert.throws(f2, /Expected a Buffer in args\[0]\./);

    function f3() {
        rsa.publicEncrypt(new Buffer(2048), ursaNative.RSA_PKCS1_OAEP_PADDING);
    }
    assert.throws(f3, /too large/);

    function f4() {
        rsa.publicEncrypt(new Buffer("x"), "str");
    }
    assert.throws(f4, /Expected a 32-bit integer/);
  });