Mocha assert.throws - I have no idea how to make it work

For Mocha Rooster Regulation project. I’ve tried looking at the documentation and another tutorial, but assert.throws is a weird one and I have no idea what it wants in order to work, and I’ve tried a couple things.

const assert = require('assert');
const Rooster = require('../index');

describe('Rooster', () => {
  describe('.timeAtDawn', () => {
    it('throws an error if passed a number less than 0', () => {
      // Define expected output
      const err = new RangeError;
      assert.throws(() => {
      }, err);

If it was coded correctly, it would pass. Instead I get the following output:

1) Rooster .timeAtDawn throws an error if passed a number less than 0:
     TypeError: is not a function
      at expectedException (assert.js:314:19)
      at _throws (assert.js:360:8)
      at Function.throws (assert.js:369:3)
      at (test/index_test.js:33:14) // this is the line with assert.throws

npm ERR! Test failed.  See above for more details.

I’ve tried other things that failed too.

I went back to mine and I didn’t have the new keyword, but I get the same issue as you if I add it in. I’m pretty sure I ran into this same issue when I went through the lesson and had to change it.

My understanding is that assert.throws() is expecting a Class, but not an instance of the Class. It also accepts other types as well, of course.

Removing new fixed it. Made sure the test passes and fails when it should, and everything is working now. I really appreciate the help.

This is definitely something I need to read up on more.