0

Apparently Very Strange Behavior in MochaJS/ChaiJS

Context

I am having a very peculiar problem with something rather straight-forward. The error actually demarcates a line in the module being tested, but I have hunted, scouted, and crusaded for the error and nothing seems to be wrong with the module. This is after being broken out into its own file, as I assumed it was my test subject's code, after a similar error to this occurred alongside several random other ones where nothing seemed to be wrong. The module has been through such heavy refactoring because of this (it has actually been rewritten now) -- and it contradicts with real, working code -- that I am extremely certain that this is an issue with Mocha, Chai, or how I am leveraging such to write tests.

There are 3 scenarios to note:

  • a) it("should do x", () => {...})
  • b) it("should do y", () => {...})
  • c) it("should do x", () => {...}) and it("should do y", () => {...})

Something important to note is that the assertion code for a and b are exactly the same -- they are exact copies. Moreover, when I replace the [basic, straight-forward, synchronous] assertion code for a & b with simple expect(true).to.equal(true|false), I do not receive the error. This suggests that I am staging my tests incorrectly.

*/**/*.spec.js


(a)
describe("Something", () => {

    it("should do x", () => {
        // constructs an object, sets some data, runs assertions.
    });

    //it("should do y", () => {
    //    // constructs an object, sets some data, runs assertions.
    //});

});
(b)
describe("Something", () => {

    //it("should do x", () => {
    //    // constructs an object, sets some data, runs assertions.
    //});

    it("should do y", () => {
        // constructs an object, sets some data, runs assertions.
    });

});
(c)
describe("Something", () => {

    it("should do x", () => {
        // constructs an object, sets some data, runs assertions.
    });

    it("should do y", () => {
        // constructs an object, sets some data, runs assertions.
    });

});

Problem

Scenarios a and b will succeed; scenario c fails. In other words, commenting out one test or the other allows the suite to pass, while having them both running leads to the suite failing.

Question

What are common or uncommon possibilities for this strange behavior?

Details

$ mocha


0 passing (5ms)



Delegations Manager (Routes & Policies)
    √ should set routes
    √ should set policies
(node:17972) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'policies' of undefined
    at DelegationsManager.map (C:\Users\Cody\projects\frameworks\motorman\src\motorman\delegations-manager.js:119:45)
    at routes.map (C:\Users\Cody\projects\frameworks\motorman\src\motorman\delegations-manager.js:99:53)
    at Array.map (<anonymous>)
    at DelegationsManager.generate (C:\Users\Cody\projects\frameworks\motorman\src\motorman\delegations-manager.js:99:36)
    at ready.then (C:\Users\Cody\projects\frameworks\motorman\src\motorman\delegations-manager.js:78:35)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:17972) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:17972) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
    √ should be ready when both routes and policies have been set
    √ should be stable when delegations bear delegates


4 passing (49ms)

@Conductor: finished execution with { code: 1, failures: 0 }

Any 1 of the tests above will pass without throwing the UnhandledPromiseRejectionWarning, however, running anymore than just 1 will throw the exception.

Cody
  • 9,785
  • 4
  • 61
  • 46

0 Answers0