首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Jasmine测试时,Ramda方法返回'undefined‘

使用Jasmine测试时,Ramda方法返回'undefined‘
EN

Stack Overflow用户
提问于 2015-12-09 07:37:53
回答 2查看 575关注 0票数 1

我正在尝试测试一些使用Ramda的代码。我用的是Jasmine和Jest

根据Jest的说法,我尝试使用的所有Ramda方法都只返回'undefined‘。

下面是代码的简化版本(我已经确认这个简化版本失败了):

代码语言:javascript
复制
 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]);
   })

 })

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

代码语言:javascript
复制
 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?

EN

回答 2

Stack Overflow用户

发布于 2015-12-11 17:17:53

你有没有用和声旗帜来运行茉莉?

无论如何,如果你避免使用let() =>,那么它就像是一个魔咒:

代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2015-12-09 08:55:26

这是否只与let语句的作用域有关?

Ramda代码当然可以工作:http://bit.ly/1jN5fkb

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

代码语言:javascript
复制
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]);
   })
})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34168180

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档