简体   繁体   English

Wallaby.js无法使用茉莉花callFake(...)?

[英]Wallaby.js not working with jasmine callFake(…)?

Problem 问题

wallaby.js seems not to be working with jasmine callFake . wallaby.js似乎不适用于茉莉花callFake I want to use the arguments passed to the original function inside the the "fake" function. 我想在“ fake”函数中使用传递给原始函数的参数。 But I always get undefined with wallaby . 但是,我总是undefinedwallaby

The test below works when running jasmine directly, but breaks when running via wallaby . 当直接运行jasmine ,下面的测试有效,但是通过wallaby运行时,该测试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);
});

在此处输入图片说明

Related info 相关资讯

Wallaby.js configuration file Wallaby.js配置文件

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 代码编辑器或IDE名称和版本

Visual Studio Code v1.21.1 Visual Studio代码v1.21.1

OS name and version 操作系统名称和版本

OSX 10.13.3 OSX 10.13.3

它是袋鼠的Jasmine 2.x支持中的一个错误, 现已修复

I found a workaround: 我找到了一种解决方法:

I used a reference to the spy inside the callFake function. 我在callFake函数中使用了对间谍的引用。 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. 但是我仍然认为这不是适当的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM