Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mocha & power-assert cannot output the descriptive assertion messages #119

Open
Rlilyyy opened this issue Jun 28, 2019 · 2 comments
Open

Comments

@Rlilyyy
Copy link

Rlilyyy commented Jun 28, 2019

I am trying to use official demo with power-assert. After Mocha run the unit test, it output func.apply(thisObj, args) insted of the descriptive assertion messages.

spec.js

const assert = require('power-assert');

describe('Array', function(){
    let ary;
    beforeEach(() => {
        ary = [1,2,3];
    });
    describe('#indexOf()', () => {
        it('should return index when the value is present', () => {
            const zero = 0, two = 2;
            assert(ary.indexOf(zero) === two);
        });
        it('should return -1 when the value is not present', () => {
            const minusOne = -1, two = 2;
            assert.ok(ary.indexOf(two) === minusOne, 'THIS IS AN ASSERTION MESSAGE');
        });
    });
});

describe('various types', () => {
    let types;
    class Person {
        constructor(name, age) {
            this.name = name;
            this.age = age;
        }
    }
    beforeEach(() => {
        types = [
            'string', 98.6, true, false, null, undefined,
            ['nested', 'array'],
            {object: true},
            NaN, Infinity,
            /^not/,
            new Person('alice', 3)
        ];
    });
    it('demo', () => {
        const index = types.length -1,
            bob = new Person('bob', 5);
        assert(types[index].name === bob.name);
    });
});

ouput

  Array
    #indexOf()
      1) should return index when the value is present
      2) should return -1 when the value is not present

  various types
    3) demo


  0 passing (15ms)
  3 failing

  1) Array
       #indexOf()
         should return index when the value is present:

      AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  func.apply(thisObj, args)

      + expected - actual

      -false
      +true
      
      at Decorator._callFunc (node_modules/empower-core/lib/decorator.js:110:20)
      at Decorator.concreteAssert (node_modules/empower-core/lib/decorator.js:103:17)
      at decoratedAssert (node_modules/empower-core/lib/decorate.js:51:30)
      at powerAssert (node_modules/empower-core/index.js:63:32)
      at Context.it (test/index.spec.js:11:7)

  2) Array
       #indexOf()
         should return -1 when the value is not present:

      AssertionError [ERR_ASSERTION]: THIS IS AN ASSERTION MESSAGE
      + expected - actual

      -false
      +true
      
      at Decorator._callFunc (node_modules/empower-core/lib/decorator.js:110:20)
      at Decorator.concreteAssert (node_modules/empower-core/lib/decorator.js:103:17)
      at Function.decoratedAssert [as ok] (node_modules/empower-core/lib/decorate.js:51:30)
      at Context.it (test/index.spec.js:15:14)

  3) various types
       demo:

      AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  func.apply(thisObj, args)

      + expected - actual

      -false
      +true
      
      at Decorator._callFunc (node_modules/empower-core/lib/decorator.js:110:20)
      at Decorator.concreteAssert (node_modules/empower-core/lib/decorator.js:103:17)
      at decoratedAssert (node_modules/empower-core/lib/decorate.js:51:30)
      at powerAssert (node_modules/empower-core/index.js:63:32)
      at Context.it (test/index.spec.js:41:5)

Mocha v6.1.4
power-assert v1.6.1
Node v10.15.2

@bannerchi
Copy link

same problem for me

@nitaking
Copy link

nitaking commented Mar 20, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants