[英]What would be a proper way of integration testing JavaScript interacting with local storage?
After listening to the JavaScript Weekly podcast, where I heard about the jQueryLocalStorageTexteareas plugin, I decided to try to implement this myself. 听完JavaScript Weekly播客之后,我听说了jQueryLocalStorageTexteareas插件,然后决定自己尝试实现此功能。
What it basically does is save a textarea's content to the browser's local storage if supported by the browser. 它的基本作用是将文本区域的内容保存到浏览器的本地存储(如果浏览器支持)。
My question is, how would I write this in a TDD style? 我的问题是,我将如何以TDD风格编写此内容? How would the highest level test implementation look like?
最高级别的测试实现会是什么样子? It should probably be something like
可能应该是这样的
when I type foo in a text area
and I close the page
and I open it again
then the text area should contain foo
Is it worth using something like Selenium to implement these kind of tests? 是否值得使用Selenium之类的东西来进行这类测试? Or is there a better way to do it?
还是有更好的方法呢?
Use a testing framework built for the job, such as qUnit. 使用为该作业构建的测试框架,例如qUnit。 jQuery-offline uses it to good effect to test caching of text using
localStorage
for browsers with and without native support. jQuery-offline很好地使用了它,可以在支持和不支持本机的浏览器中使用
localStorage
测试文本缓存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.