NodeJS with jasmine and jasmine-expect passes once then fails #786

jessezhang91 opened this Issue Sep 11, 2016 · 1 comment


None yet

2 participants


Issue description or question

I'm not sure if I'm requiring jasmine-expect correctly but my assertions like expect(arr).toBeArrayOfObjects(); seem to be passing the first time. Subsequent runs of the spec causes it to throw ​​expect(...).toBeArrayOfObjects is not a function​​. If I stop and start wallaby, the test passes again.

Wallaby.js configuration file

"use strict";

module.exports = (w) => {
    return {
        files: [
        tests: [
        compilers: {
            "**/*.ts": w.compilers.typeScript({
                target: "es5",
                module: "commonjs",
                typescript: require("typescript")
        env: {
            type: "node"
        testFramework: "jasmine",
        setup: (w) => {
            w.testFramework.DEFAULT_TIMEOUT_INTERVAL = 2500;

Code editor or IDE name and version

Visual Studio Code v1.5.1

OS name and version



Wallaby.js reuses node processes by default and jasmine-expect is built in such a way that it only adds matchers once per process, so when the setup function executes require("jasmine-expect"); second time in the same process, nothing happens.

The easiest way to test if it's an issue for any scenario/module is to try and set workers.recycle setting to true to make wallaby.js re-start node process for each run. If it works fine with the setting, you may either keep using it, or try resetting the node cache for the module so that it can work even with the process re-use (which is more performant than restarting node processes).

By quickly trying, here is the solution that seems to work in this specific case:

    setup: (w) => {
      Object.keys(require.cache).filter(k => k.indexOf('jasmine-expect') >= 0)
        .forEach((k) => { delete require.cache[k]; });

      w.testFramework.DEFAULT_TIMEOUT_INTERVAL = 2500;

I just delete the jasmine-expect module from the node cache before require-ing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment