我注意到,如果我使用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
的减少是保持某种状态或分享words
对方。我不确定这是如何发生的。任何人都知道我应该使用Google搜索或者处理此问题的其他人的文档/示例?
这看起来像为数组的'reduce'实现https://github.com/ramda/ramda/blob/master/src/internal/_reduce.js#L7-L19 – elclanrs
@elclanrs感谢您指出'减少'不需要索引。由于某些原因,添加索引不会改变我的测试仍然失败。我已经更新了要点来反映这一点。 –