How to use the assert/.strictEqual 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 nodejs / readable-stream / test / parallel / test-stream3-pause-then-read.js View on Github external
(function read() {
    var c = r.read(n);
    console.error('c', c);
    if (!c) r.once('readable', read);else {
      assert.strictEqual(c.length, n);
      assert(!r.readableFlowing);
      then();
    }
  })();
} // then we listen to some data events
github nodejs / readable-stream / test / parallel / test-stream-big-push.js View on Github external
r.once('readable', function () {
  // this time, we'll get *all* the remaining data, because
  // it's been added synchronously, as the read WOULD take
  // us below the hwm, and so it triggered a _read() again,
  // which synchronously added more, which we then return.
  chunk = r.read();
  assert.strictEqual(chunk, str + str);
  chunk = r.read();
  assert.strictEqual(chunk, null);
});
;
github nodejs / readable-stream / test / parallel / test-stream-pipe-unpipe-streams.js View on Github external
var source = Readable({
  read: function read() {}
});
var dest1 = Writable({
  write: function write() {}
});
var dest2 = Writable({
  write: function write() {}
});
source.pipe(dest1);
source.pipe(dest2);
dest1.on('unpipe', common.mustCall());
dest2.on('unpipe', common.mustCall());
assert.strictEqual(source._readableState.pipes[0], dest1);
assert.strictEqual(source._readableState.pipes[1], dest2);
assert.strictEqual(source._readableState.pipes.length, 2); // Should be able to unpipe them in the reverse order that they were piped.

source.unpipe(dest2);
assert.strictEqual(source._readableState.pipes, dest1);
assert.notStrictEqual(source._readableState.pipes, dest2);
dest2.on('unpipe', common.mustNotCall());
source.unpipe(dest2);
source.unpipe(dest1);
assert.strictEqual(source._readableState.pipes, null);
{
  var checkDestCleanup = function checkDestCleanup(dest) {
    var currentDestId = ++destCount;

    _source.pipe(dest);

    var unpipeChecker = common.mustCall(function () {
github nodejs / readable-stream / test / parallel / test-stream-pipeline-queued-end-in-destroy.js View on Github external
pipeline(readable, duplex, common.mustCall(function (err) {
  assert.strictEqual(err.code, 'ERR_STREAM_PREMATURE_CLOSE');
})); // Write one chunk of data, and destroy the stream later.
// That should trigger the pipeline destruction.
github nodejs / readable-stream / test / parallel / test-stream-readable-async-iterators.js View on Github external
try {
            if (!_iteratorNormalCompletion6 && _iterator6.return != null) {
              yield _iterator6.return();
            }
          } finally {
            if (_didIteratorError6) {
              throw _iteratorError6;
            }
          }
        }
      } catch (e) {
        _err4 = e;
      }

      assert.strictEqual(_err4.message, 'kaboom');
      assert.strictEqual(_received2, 1);
    }
    {
      console.log('push async');
      var _max3 = 42;
      var _readed = 0;
      var _received3 = 0;

      var _readable10 = new Readable({
        objectMode: true,
        read: function read() {
          var _this2 = this;

          setImmediate(function () {
            _this2.push('hello');

            if (++_readed === _max3) {
github nodejs / readable-stream / test / parallel / test-stream-readable-async-iterators.js View on Github external
try {
            if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
              yield _iterator4.return();
            }
          } finally {
            if (_didIteratorError4) {
              throw _iteratorError4;
            }
          }
        }
      } catch (e) {
        _err2 = e;
      }

      assert.strictEqual(_err2.message, 'kaboom');
      assert.strictEqual(_received, 1);
    }
    {
      console.log('destroyed by throw');

      var _readable8 = new Readable({
        objectMode: true,
        read: function read() {
          this.push('hello');
        }
      });

      var _err3 = null;

      try {
        var _iteratorNormalCompletion5 = true;
        var _didIteratorError5 = false;
github nodejs / readable-stream / test / parallel / test-stream2-basic.js View on Github external
w3.end = common.mustCall(function () {
    assert.strictEqual(counter, 2);
    assert.strictEqual(expected.length, 0);
  });
}
github nodejs / readable-stream / test / parallel / test-stream-transform-split-objectmode.js View on Github external
require('../common');

var assert = require('assert/');

var Transform = require('../../').Transform;

var parser = new Transform({
  readableObjectMode: true
});
assert(parser._readableState.objectMode);
assert(!parser._writableState.objectMode);
assert.strictEqual(parser.readableHighWaterMark, 16);
assert.strictEqual(parser.writableHighWaterMark, 16 * 1024);
assert.strictEqual(parser.readableHighWaterMark, parser._readableState.highWaterMark);
assert.strictEqual(parser.writableHighWaterMark, parser._writableState.highWaterMark);

parser._transform = function (chunk, enc, callback) {
  callback(null, {
    val: chunk[0]
  });
};

var parsed;
parser.on('data', function (obj) {
  parsed = obj;
});
parser.end(bufferShim.from([42]));
process.on('exit', function () {
  assert.strictEqual(parsed.val, 42);
});
var serializer = new Transform({
github nodejs / readable-stream / test / parallel / test-stream-readable-hwm-0.js View on Github external
process.nextTick(function () {
  assert.strictEqual(r.read(), null);
  pushedNull = true;
  r.push(null);
});
;
github nodejs / readable-stream / test / parallel / test-stream-writable-needdrain-state.js View on Github external
function _transform(chunk, encoding, cb) {
  assert.strictEqual(transform._writableState.needDrain, true);
  cb();
}