Reverse Zen Coding

给你一囗甜甜゛ 提交于 2019-12-13 14:12:52

问题


I'm writing a javascript unit test suite and one of the features I'd like to add is the ability to assert that a certain element and its children match a given HTML structure.

My first idea is to use jQuery (well, Sizzle) and ask that users write Zen Code statements to make assertions. My first question is "Has this been done before? Can I steal it?". If not, is there a specification printed anywhere for how to parse a Zen Code statement? Are there any shortcuts I could make, given the power of Sizzle?


回答1:


I think you can get there with sizzle + http://api.jquery.com/size/

The example zen code query is "div#page>div.logo+ul#navigation>li*5>a". Testing if a page has that same structure in jQuery would be as easy as $("div#page > div.logo + ul#navigation > li > a").size() == 5.

Unless your users are already familiar with zen code, tests with an api like assertSelects(selector, number_of_returned_items) should be cozier.



来源:https://stackoverflow.com/questions/4864261/reverse-zen-coding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!