tape-testing / tape

tap-producing test harness for node and browsers
MIT License
5.77k stars 307 forks source link

async test failing in v5.0.0 #510

Closed rvillane closed 4 years ago

rvillane commented 4 years ago

Hi, this test worked fine in v4.x.x:

    test('Order - ani status', t => {
        const orderInfo = getBaseOrderInfo();
        orderInfo.properties.aniSatatusIndicator = ' ';
        orderInfo.properties.type = '05';
        sut.transformOrder(orderInfo).then(result => {
            t.equal(result.order.aniStatusInd, 'E');
        });
        orderInfo.properties.type = Constants.returnOrderTypeInd;
        sut.transformOrder(orderInfo).then(result => {
            t.equal(result.order.aniStatusInd, 'A');
        });
        orderInfo.properties.type = Constants.exchangeOrderTypeInd;
        sut.transformOrder(orderInfo).then(result => {
            t.equal(result.order.aniStatusInd, 'A');
        });
        orderInfo.properties.type = Constants.repairOrderTypeInd;
        sut.transformOrder(orderInfo).then(result => {
            t.equal(result.order.aniStatusInd, 'A');
        });
        t.end();
    });

now is failing with v5.0.0:

 operator: fail
    at: sut.transformOrder.then.result (/Users/crmar/GitHub_Storage/direct-order-transformer/tests/order-transformer-test.js:171:15)
    stack: |-
      Error: .end() already called: should be strictly equal
          at Test.assert [as _assert] (/Users/crmar/GitHub_Storage/direct-order-transformer/node_modules/tape/lib/test.js:260:54)
          at Test.bound [as _assert] (/Users/crmar/GitHub_Storage/direct-order-transformer/node_modules/tape/lib/test.js:84:32)
          at Test.fail (/Users/crmar/GitHub_Storage/direct-order-transformer/node_modules/tape/lib/test.js:354:10)
          at Test.bound [as fail] (/Users/crmar/GitHub_Storage/direct-order-transformer/node_modules/tape/lib/test.js:84:32)
          at Test.assert [as _assert] (/Users/crmar/GitHub_Storage/direct-order-transformer/node_modules/tape/lib/test.js:238:14)
          at Test.bound [as _assert] (/Users/crmar/GitHub_Storage/direct-order-transformer/node_modules/tape/lib/test.js:84:32)
          at Test.strictEqual (/Users/crmar/GitHub_Storage/direct-order-transformer/node_modules/tape/lib/test.js:424:10)
          at Test.bound [as equal] (/Users/crmar/GitHub_Storage/direct-order-transformer/node_modules/tape/lib/test.js:84:32)
          at sut.transformOrder.then.result (/Users/crmar/GitHub_Storage/direct-order-transformer/tests/order-transformer-test.js:171:15)
          at process._tickCallback (internal/process/next_tick.js:68:7)

any recommendations about what needs to be refactored on my code ? thanks

ljharb commented 4 years ago

Yep! You always had an issue, unfortunately :-/

Asynchronous tests need t.plan. Your test should start with t.plan(4), and shouldn't contain t.end() at all.

An alternative is to remove both, to make your test function an async function, and to await every promise (rather than using .then).

rvillane commented 4 years ago

adding t.plan(x) and removing t.end() is fixing the problem, thanks.