0

Problem

wallaby.js seems not to be working with jasmine callFake. I want to use the arguments passed to the original function inside the the "fake" function. But I always get undefined with wallaby.

The test below works when running jasmine directly, but breaks when running via wallaby.

Did this happen with anyone else? Any ideas on how to fix it?

Test

it('test callFake and wallaby', async () => {
  // Arrange
  const myObj = {
    myFunc: (a) => a + 1,
  };

  spyOn(myObj, 'myFunc')
    .and.callFake(arg => arg);

  // Act
  const result = myObj.myFunc(1);

  // Assert
  expect(result).toBe(1);
});

enter image description here

Related info

Wallaby.js configuration file

module.exports = (wallaby) => {
  return {
    files: [
      'src/**/*.js',
      'migrations/*',
      'test/_helpers/*',
      'seeds/*',
      'config/*',
      { pattern: '.env', instrument: false },
    ],

    tests: [
      'test/**/*.spec.js',
    ],

    compilers: {
      '**/*.js': wallaby.compilers.babel(),
    },

    testFramework: 'jasmine',

    env: {
      type: 'node',

      params: {
        env: 'NODE_ENV=test;MONGODB_CONQUERY=mongodb://localhost:27017/athena-test',
      },
    },
    workers: {
      initial: 1,
      regular: 1,
      restart: true,
    },

    setup: (/* wallaby */) => {
      require('dotenv').load({ path: '.env' }); // eslint-disable-line
      require('./test/_helpers/dropDatabase'); // eslint-disable-line
    },

    teardown: (/* wallaby */) => {
    },
  };
};

Code editor or IDE name and version

Visual Studio Code v1.21.1

OS name and version

OSX 10.13.3

Joilson Cisne
  • 187
  • 10

2 Answers2

1

It was a bug in Jasmine 2.x support in wallaby it is fixed now.

Artem Govorov
  • 903
  • 6
  • 10
0

I found a workaround:

I used a reference to the spy inside the callFake function. See on the code below:

it('test callFake and wallaby', async () => {
    // Arrange
    const myObj = {
      myFunc: (a) => a + 1,
    };

    const spy = spyOn(myObj, 'myFunc')
      .and.callFake(
        () => spy.calls.argsFor(0)[0]
      );
    // Act
    const result = myObj.myFunc(1);

    // Assert
    expect(result).toBe(1);
  });

But I still think this is not the proper behaviour.

Joilson Cisne
  • 187
  • 10