我正在尝试测试一些使用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?
发布于 2015-12-11 17:17:53
你有没有用和声旗帜来运行茉莉?
无论如何,如果你避免使用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]);
});
});发布于 2015-12-09 08:55:26
这是否只与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]);
})
})https://stackoverflow.com/questions/34168180
复制相似问题