使用Mocha进行无头敲除ViewModel测试 [英] Headless knockout viewmodel testing with mocha

查看:88
本文介绍了使用Mocha进行无头敲除ViewModel测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对剔除视图模型进行无意义的测试.我故意避免在我的viewmodel中处理任何ui构造,而将联结留给html页面.

I am trying to do headless testing of my knockout viewmodels. I purposely avoid dealing with any ui constructs in my viewmodel and leave the wireup to the html page.

这在Jasmine中非常有效,因为它在浏览器中运行,但是当我切换到 mocha 时,我最终进入淘汰赛的最后一行是

This works great in Jasmine since it runs in the browser, but when I switch to mocha, I end up running head-first into the last line on knockout which is:

})(窗口,文档,导航器);

})(window,document,navigator);

我已经看过使用 zombiejs ,这是一个不错的选择,但我看不到关于如何使用它而不改变淘汰源本身的好故事.

I've looked at using zombiejs which would be a nice alternative, but I don't see a good story on how to use it without changing the knockout source itself.

关于如何处理此问题的任何想法?

Any thoughts on how to approach this?

推荐答案

这也是我目前关注的话题.我将我的发现转储到这里,希望它们可以为您指明正确的方向.

This is a topic currently on my radar as well. I'll dump my findings here in the hopes that they might point you in the right direction.

我首先尝试的可能路径是 PhantomJS .这是一款无头的WebKit浏览器,因此它应该具有出色的DOM,JSON,HTML5和CSS选择器支持(它

The likely route I will attempt first will be PhantomJS. It's a headless WebKit browser, so it should have excellent DOM, JSON, HTML5, and CSS selectors support (it works with jQuery and qUnit, for example).

之所以选择它,是因为它是由kickout.js本身使用的,我在knockout.js存储库中发现了该存储库,该存储库中有一个.travis.yml文件和以下注释:

I chose this because it is used by knockout.js itself, which I discovered in the knockout.js repository, where there was a .travis.yml file and this comment:

我没有任何证据可以证明这是行得通的,但是由于它在敲门(knockout.js)内核中的使用而受到鼓舞.我还发现了用于淘汰赛/幻影的赛跑者脚本看起来是一个很好的启动点.

I don't have any proof that this is going to work, but was encouraged by its use in knockout.js core. I also found this runner script for knockout/phantom that looks like a great launch point.

我还找到了 a 示例通过node.js使用Mocha和PhantomJS,包括此库扩展了grunt 以便在Phantom内部运行mocha ,以及此脚本显示了如何在PhantomJS中运行摩卡.因此,至少这部分是确定的.

I've also found a few examples using Mocha and PhantomJS via node.js, including this lib extending grunt to run mocha inside Phantom, and this script showing how to run mocha inside PhantomJS. So that part is certain, at the very least.

注意到的另一种解决方案是使用淘汰节点

Another solution noted in the knockoutjs archives, is to use knockout-node and JsDOM to create a workable DOM, but at first glance, this seemed too nebulous and likely to result in implementing your own test environment.

有一个

There is a slidedeck suggesting zombie.js would work with knockout/node/etc. But I can't find anything offering hard evidence, so I didn't like this route either.

这篇关于使用Mocha进行无头敲除ViewModel测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆