【发布时间】:2017-09-12 14:52:36
【问题描述】:
我注意到,如果我使用ramda,有时我会在尝试为我正在导出的方法编写Jest 测试时遇到问题。我将问题归结为以下测试和两个基本的减速器功能。我已将它们发布在 gist 上,以免代码堵塞这个问题。
https://gist.github.com/beardedtim/99aabe3b08ba58037b20d65343ed9d20
ramda 减速器出现以下错误:
● counter usage › counter counts the words and their index in the given list of words
expect(received).toEqual(expected)
Expected value to equal:
[{"count": 3, "indexes": [0, 2, 4], "value": "a"}, {"count": 1, "indexes": [1], "value": "b"}, {"count": 1, "indexes": [3], "value": "c"}]
Received:
[{"count": 15, "indexes": [0, 2, 4, 0, 2, 4, 0, 2, 4, 0, 2, 4, 0, 2, 4], "value": "a"}, {"count": 5, "indexes": [1, 1, 1, 1, 1], "value": "b"}, {"count": 5, "indexes": [3, 3, 3, 3, 3
], "value": "c"}]
这让我相信ramda 的reduce 是保持某种状态或彼此共享words。我不确定这是怎么发生的。有人知道我应该在谷歌上搜索什么或其他处理此问题的一些文档/示例吗?
【问题讨论】:
-
这看起来像是数组
reduce的实现github.com/ramda/ramda/blob/master/src/internal/… -
@elclanrs 感谢您指出
reduce没有索引。添加索引不会改变我的测试由于某种原因仍然失败。我已经更新了要点以反映这一点。
标签: javascript unit-testing jestjs ramda.js babel-jest