Skip to content

Instantly share code, notes, and snippets.

@haingdc
Last active April 10, 2018 03:26
Show Gist options
  • Save haingdc/5693c5d5623be6937dbf602c50b771fe to your computer and use it in GitHub Desktop.
Save haingdc/5693c5d5623be6937dbf602c50b771fe to your computer and use it in GitHub Desktop.
Thao tác với DOM thông qua TDD
// photo-lister-spec.js
var cheerio = require("cheerio");
// ... lược bỏ ...
describe("#addPhotosToElement()", function() {
it("should take an HTML string of list items and add them to an element with a given selector", function() {
var $ = cheerio.load( // 🦊
'<html><head></head><body><div id="mydiv"></div></body></html>',
),
list =
'<ul><li><figure><img src="http://loremflickr.com/960/593" alt=""/>' +
"<figcaption>This is a test</figcaption></figure></li>" +
'<li><figure><img src="http://loremflickr.com/960/593/puppy" alt=""/>' +
"<figcaption>This is another test</figcaption></figure></li></ul>",
selector = "#mydiv",
$div = PhotoLister.addPhotosToElement($, selector, list);
expect($div.find("ul").length).to.equal(1);
expect($div.find("li").length).to.equal(2);
expect($div.find("figure").length).to.equal(2);
expect($div.find("img").length).to.equal(2);
expect($div.find("figcaption").length).to.equal(2);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment