Testing JavaScript readline with Jasmine
Testing JavaScript readline with Jasmine
我有一个名为move的函数,允许用户输入答案。
move:function() {
print("Enter number between 1 - 9");
var userInput = readline();
counter++
}
我的茉莉花测试是这样的
it("takes turn playing pieces", function() {
counter = 2;
game = new PlayGame();
game.move()
expect(counter).toEqual(3)
}
错误信息: ReferenceError: readline is not defined。我觉得问题是jasmine不知道readline是什么。我希望在测试套件中获得用户输入的事实似乎是不对的。我可以测试什么呢?
,而只是看看我是否得到了正确的输出(这就是为什么我要测试counter。你们怎么看?
您可以将readline()
替换为方法调用ui.readline()
(对象ui是readline等方法的包装器)-然后在测试中您可以监视readline方法:
spyOn(ui, 'readline');
相关文章:
- Fighting with FRP
- issue with FB.Event.subscribe
- 使用jasmine模拟对服务器的调用
- geolocation-marker.js conflict with markerclusterer.js
- Angular 2.0 with JavaScript or TypeScript?
- 为什么不推荐使用“with”?是否有更好或其他方法可以“下降”到对象的命名空间
- WebComponentsJS with IE10
- 为什么jasmine期望不验证是否抛出了错误
- 模拟chrome.storage.local函数使用Jasmine
- 指令的模板必须只有一个根元素:With restrict E&替换true
- Jasmine Testing with Angular Promise 无法使用 TypeScript 解析
- JavaScript: toLocaleString() testing with jasmine
- 单元测试窗口.onerror with jasmine.
- Jasmine和Karma with Jasmine给出了不同的结果
- Testing Moment.js with Jasmine
- AngularJS控制器的Unittest with Jasmine and Karma "无法读取属性
- Testing jQuery Hover with Jasmine
- Running jasmine specs headlessly with phantomjs
- Spying on console.error() with Jasmine
- Testing JavaScript readline with Jasmine