我正在尝试测试一些使用Ramda的代码。我使用的是Jasmine和Jest。
根据Jest的说法,我试图使用的所有Ramda方法只返回' undefined'
这是代码的简化版本(我已确认此简化版本失败):
let R = require('ramda')
let arr = [0, 1, 2]
let newArr = R.adjust(R.add(10), 1, arr)
describe('adjust', function() {
it('should apply the function only to the second element in the array', () => {
expect(newArr).toBe([0, 11, 2]);
})
})
这是我在运行测试时收到的错误消息:
FAIL tests/functional-programming/ramda/lists/adjust.test.js (0.855s)
● adjust › it should apply the function only to the second element in the array
- Expected: undefined toBe: {
| 0: 0,
| 1: 11,
| 2: 2
}
at Spec.<anonymous> (tests/functional-programming/ramda/lists/adjust.test.js:12:20)
1 test failed, 51 tests passed (52 total in 15 test suites, run time 3.07s)
我不确定上述代码有什么问题。为什么newArr的值是undefined?
答案 0 :(得分:1)
你以某种方式运行茉莉花与和谐旗帜?
无论如何,如果您避免使用let
和() =>
,那么它就像魅力一样:
var R = require('ramda');
var arr = [0,1,2];
var newArr = R.adjust(R.add(10), 1, arr);
describe("adjust", function() {
it("should apply the function only to the second element", function() {
// replaced toBe with toEqual matcher
expect(newArr).toEqual([0,11,2]);
});
});
答案 1 :(得分:0)
这只是与let
声明的范围有关吗?
Ramda代码肯定有效:http://bit.ly/1jN5fkb
如果你像这样重新安排它是否有效?:
let R = require('ramda')
describe('adjust', function() {
let arr = [0, 1, 2]
let newArr = R.adjust(R.add(10), 1, arr)
it('should apply the function only to the second element in the array', () => {
expect(newArr).toBe([0, 11, 2]);
})
})