Jasmine Ramda方法返回';未定义';用茉莉花测试时

Jasmine Ramda方法返回';未定义';用茉莉花测试时,jasmine,jestjs,ramda.js,Jasmine,Jestjs,Ramda.js,我正在尝试测试一些使用的代码。我在用茉莉花和玩笑 Jest说,我尝试使用的所有Ramda方法都只返回“undefined” 下面是代码的简化版本(我已确认此简化版本失败): 这是我在运行测试时收到的错误消息: FAIL tests/functional-programming/ramda/lists/adjust.test.js (0.855s) ● adjust › it should apply the function only to the second element in th

我正在尝试测试一些使用的代码。我在用茉莉花和玩笑

Jest说,我尝试使用的所有Ramda方法都只返回“undefined”

下面是代码的简化版本(我已确认此简化版本失败):

这是我在运行测试时收到的错误消息:

 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)
失败测试/功能编程/ramda/list/adjust.test.js(0.855s)
● 调整›应仅将该功能应用于阵列中的第二个元素
-预期:未定义toBe:{
| 0: 0,
| 1: 11,
| 2: 2
}
按照规范(tests/functional programming/ramda/list/adjust.test.js:12:20)
1个测试失败,51个测试通过(15个测试套件共52个,运行时间3.07s)

我不确定上面的代码有什么问题。为什么newArr的值为undefined

这是否与您的
let
语句的范围有关

拉姆达代码当然有效:

如果你像这样重新排列,它会起作用吗

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]);
   })
})

你有没有用和声旗管理茉莉花

无论如何,如果您避免使用
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]);
  });
});

不幸的是,
expected(newArr)
仍然返回
undefined
,我甚至尝试粘贴到您的代码块并运行测试套件。这与操作顺序有关吗?或者Ramda在库中大量使用curry与
R.adjust()
返回
未定义的
,有什么关系吗?简单地避免ES6/ES2015并不是一个真正的解决方案——我试图弄清楚为什么在这种情况下会出现范围问题。
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]);
  });
});