DigitalHistory / assignment-01-html-css

Web Skills/programming assignment for "Digital History" at University of Toronto
http://digital.hackinghistory.ca
2 stars 38 forks source link

rewrite cheerio with newer jsdom/jquery #24

Open titaniumbones opened 5 years ago

titaniumbones commented 5 years ago

This would also close #22 #21 and #20.

It's possible to load the page asynchronously in jsdom & then add jquery. This allows the querying of computed css values.

Here is some code that works:

  before(async function() {
    let jsdom = await JSDOM.fromFile("05/index.html", {
      resources: "usable",
      runScripts: "dangerously"
    });

    await new Promise(resolve =>
      jsdom.window.addEventListener("load", resolve)      
    );
    let window  = jsdom.window;
    let {document } = global.document = window;
    // global scope absolutely required unfortunately
    let $ = global.$ = require('jquery')(window);
  });

tests then become generally more reliable.

working on this in another branch.

titaniumbones commented 5 years ago

Committed much of this for som problems. Early problems still use cherio, would be nice to lose the dependency.

titaniumbones commented 4 years ago

I'm running into some problems with this; it's not easy to get into the internals of the jquery object. For instance, this test fails because object [0] doesn't seem to exist:

expect($('header div.senderinfo p a')[0].attribs.href, 'href').to.include('mailto:') ;