javascript-似乎找不到有关测试Cycle.js应用程序的资源
作者:互联网
我一直在尝试搜索有关测试Cycle.js应用程序的指南,但似乎找不到.有人可以向我指出指南或提供一些示例吗?
解决方法:
从Cycle.js.org开始:
Sources and sinks can be easily used as 07001. This also means testing is mostly a matter of feeding inputs and inspecting the output. No deep mocking needed. Your application is just a pure transformation of data.
实际上,从Cycle.js核心的GitHub issue版本开始,Cycle.js的作者AndréStaltz解释说:
Testing Cycle.js code is basically just about testing Observables
最简单的测试采用以下形式:
// Create the mocked user events
const userEvents = mockDOMSource(...);
// Use them in your tests against `main`
const sinks = main({DOM: userEvents});
sinks.DOM.subscribe(function (vtree) {
// make assertions here on the vtree
});
注意,这里我们使用了mockDOMSource.
rx.js v5.3.0发布了mockDOMResponse,后来被重命名为mockDOMSource.它是一个易于模拟用户交互的功能(模拟DOM.select(‘.foo’).events(‘click’)之类的意图).
这是example:
test('CounterButton should increment number by 1 when clicked', t => {
t.plan(4)
const DOM = mockDOMSource({'.inc': {click: Observable.repeat({}, 3)}})
const sinks = CounterButton({DOM})
sinks.DOM
.take(4)
.toArray()
.subscribe(vtrees => {
const counts = vtrees.map(vt => vt.children[0].text.match(/\d+$/)[0])
t.equal(counts[0], '0', 'button has count 0')
t.equal(counts[1], '1', 'button has count 1')
t.equal(counts[2], '2', 'button has count 2')
t.equal(counts[3], '3', 'button has count 3')
})
})
如果您在GitHub上进行全局搜索,以获取模拟DOMSource here和模拟DOMResponse here
那么您可以进行Cycle.js测试的find some examples.
您也可以检出Awesome Cycle.js回购的Testing section.
旁注:很快我们将能够编写Marble Tests.不幸的是,目前仅支持rxjs v4的Cycle.js 6无法实现.
大理石测试是rxjs v5的新功能.参见:Rxjs testing – is it possible to use marble diagrams also in RxJs 4?
标签:testing,web,reactive-programming,cyclejs,javascript 来源: https://codeday.me/bug/20191027/1944445.html