我们用了大约一年的时间,用不变的数据,非常令人印象深刻。我们现在想转移到Clojurescript/Reagent,但是我们需要一种非常好的方法来测试我们的代码。对于组件,这就是我们所做的:
对于一个人来说,就像:
function renderFFC(filters, search_criterias)
{
return TestUtils.renderIntoDocument(React.createElement(FilterIntervalNumberComponent,{filter:filters, search_criteria:search_criterias}));
}
describe("IN", function(){
it("should render search criteria - interval", function() {
var criterias = {};
var ffc = renderFFC(filter, criterias);
expect(ffc.refs[0].getDOMNode().value).toBeNull();
expect(ffc.refs[1].getDOMNode().value).toBeNull();
});对于两个人来说,应该是这样的:
describe("OUT", function(){
it("should change the values, then click - boolean ", function() {
//mock function
set_criteria_and_search = jest.genMockFunction();
var fbc = renderFBC(filter, {});
React.addons.TestUtils.Simulate.change(fbc.refs.yes.getDOMNode(),{nativeEvent: {target: {value: true}}});
expect(controller.set_criteria_and_search.mock.calls)
.toEqual(
[['taxes_applied',{'taxes_applied':[{value:"1"}]}]]
);
});我们用facebook Jest做测试。
我如何使用Reagent在Clojurescript中做同样的事情,最好让测试自动运行?
发布于 2015-12-22 17:12:12
测试试剂组分:
测试组件输出。组件:
(defn weather-component [city temp country]
[:div#weather
[:h2#city {:on-click #(do-something 101)} city ]
[:h3#temp temp]
[:h3#contry country]])测试:
(deftest weather-component-test-in
;;WHEN render component in test
(let [comp (r/render-component [w/weather-component "Paris" 12]
(. js/document (getElementById "test")))]
;;ASSERT
(is (= (d/html (sel1 :#city)) "Paris"))
(is (= (d/html (sel1 :#temp)) "12"))))测试当像单击这样的事件发生时,组件调用正确的函数并使用正确的参数调用
(deftest weather-component-test-out
(let [comp (r/render-component [w/weather-component "London" 0]
(. js/document (getElementById "test")))
expected-invocations (atom [])]
(with-redefs [weather-app.core/do-something #(swap! expected-invocations conj %)]
(sim/click (sel1 :#city) {})
(is (=[101] @expected-invocations)))))要操作dom并模拟事件:
cljs-react测试“0.1.3-快照”和dommy (d/.)
https://stackoverflow.com/questions/34180048
复制相似问题