[英]Wallaby.js not working with jasmine callFake(…)?
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
. 但是,我总是
undefined
与wallaby
。
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?
关于如何解决它的任何想法?
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);
});
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 */) => {
},
};
};
Visual Studio Code v1.21.1 Visual Studio代码v1.21.1
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.