开发者

Reverse Zen Coding

开发者 https://www.devze.com 2023-02-08 10:23 出处:网络
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.

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号