The assert.approximately is inputed by number,but get error expected number

The assert.approximately is inputed by number,but get error expected number
0

#1

definitions approximately(actual, expected, delta, [message])
@param { Number } actual
@param { Number } expected
@param { Number } delta
@param { String } message
suite(‘Function convertHandler.convert(num, unit)’, function() {

    test('Gal to L', function(done) {
      var input = [5, 'gal'];
      var expected = 18.9271;
      console.log(!isNaN((convertHandler.convert(input[0],input[1]))))// get true
      assert.approximately(convertHandler.convert(input[0],input[1]),expected,0.1); //0.1 tolerance
      done();
    });

Function convertHandler.convert(num, unit)
12:54 PM
true

  1) Gal to L
  1. Unit Tests

    Function convertHandler.convert(num, unit)

     Gal to L:
    

    AssertionError: expected ‘18.92705’ to be a number

    at Context. (tests/1_unit-tests.js:112:14)
    I solved by formatting Number()


#2

hi! I cannot tell if you are asking anything above or making a comment… Can you clarify your post?


#3

Maybe. I don’t, understand the check with NaN say is a number , but I must again formatting number as Number(number), why?


#4

The reason may be because the value you are checking is a string. IsNaN will try to coerce the string to number and if that succeeds it will say false is the result.
See the full documentation here