0

I am trying to test a function that when an undefined variable is passed in, it should not throw TypeError:

describe('myFunction', function () {
    it('should not throw TypeError =>', function () {
        var x = undefined;
        chai.expect(myFunction(x)).to.not.throw(TypeError)
    }):
});

But it still throws the error.

Sachihiro
  • 1,597
  • 2
  • 20
  • 46
  • @Phil, i need to not throw, the duplicate that you are suggesting are for cases when you want to throw an error. – Sachihiro Feb 14 '19 at 00:22
  • Sounds like your function fails this test then. In any case, you should still pass a function to `expect()` so your assertion can operate on the result, even if it does throw an error – Phil Feb 14 '19 at 00:24
  • I pass myFunction(x) at expect(), and x is a undefined variable. – Sachihiro Feb 14 '19 at 00:27
  • I don't think you've looked closely enough at the duplicate. Try `expect(() => myFunction(x))` or `expect(function() { myFunction(x) })` if you don't like arrow functions – Phil Feb 14 '19 at 00:28
  • You are correct. Thanks :) – Sachihiro Feb 14 '19 at 00:33

0 Answers0