Duplicating Node.js `assert` assertions in spec `expect`
<p>As opposed to non-asserted code with custom developer-friendly checks,</p>

<pre><code>class Some {
  constructor(arg) {
    if (Array.isArray(arg) &amp;&amp; arg[0] === 'foo')
      this.foobar = arg.concat('bar').join('');
    else
      console.error('Bad Some constructor arg');
  }
}
</code></pre>

<p>currently tested code is heavily packed with Node <code>assert</code> assertions with reasonably meaningful <code>message</code> arguments:</p>

<pre><code>class Some {
  constructor(arg) {
    assert.deepEqual(arg, ['foo'], 'Some constructor arg');
    this.foobar = arg.concat('bar').join('');
  }
}
</code></pre>

<p>The assertion is there to</p>

<ul>
<li>keep the code flat and readable</li>
<li>provide meaningful feedback on incorrect usage with call stack</li>
<li>prevent function execution and don't propagate the error further</li>
<li>throw an error and leave error handling to caller</li>
</ul>

<p>Current spec may look like that:</p>

<pre><code>it('...', () =&gt; {
  let some = new Some(['foo']);
  expect(some).to...
</code></pre>

<p>And it will pass - desirable usage is asserted in spec, undesirable usage it asserted in tested code.</p>

<p>To overlap code assertions in part it may be even</p>

<pre><code>it('...', () =&gt; {
  const { AssertionError } = require('assert');
  let some = new Some(['foo']);
  expect(some).to...
  expect(() =&gt; new Some(['bar']).to.throw(AssertionError);
</code></pre>

<p>So we basically assume here that half of testing job was already done in the code itself with <code>assert</code> and skip the details (<code>to.not.throw</code> and matching AssertionError messages).</p>

<p>The example above uses Mocha+Chai, but the same thing applies to Jasmine.</p>

<ul>
<li><p>Should app assertions be treated as any other code lines and doubled with spec assertions (<em>to throw</em>, <em>to not throw</em>, <code>AssertionError</code> message matching), what are the consequences of taking a shortcut?</p></li>
<li><p>Can test coverage tools (Istanbul) take into account <code>assert</code> assertions in app code in addition to <code>expect</code>?</p></li>
<li><p>May test runners be confused by the fact that it was app, not spec assertion that threw an error?</p></li>
</ul>

<p>Some examples of successful open-source JS projects that prove or refute 'assert assert assertions' point in practice could be also helpful.</p>