Skip to content

Instantly share code, notes, and snippets.

@mjschranz
Created June 27, 2012 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mjschranz/3004993 to your computer and use it in GitHub Desktop.
Save mjschranz/3004993 to your computer and use it in GitHub Desktop.
Page Tests
/*global text,expect,ok,module,notEqual,Butter,test,window*/
(function (window, document, Butter, undefined) {
require( [ "../src/core/page", "../src/core/config", "../src/dependencies" ],
function( Page, Config, Dependencies ) {
var _config = Config.parse( '{ "test": "derp" }' ),
_loader = Dependencies( _config ),
_page = new Page( _loader, _config );
test( "Page - scrape media target and media elements", 3, function() {
var scrapedPage;
scrapedPage = _page.scrape();
ok( scrapedPage, "Scrape Returned an Object" );
equal( scrapedPage.media.length, 2, "Scrape retrieved two media elements" );
equal( scrapedPage.target.length, 2, "Scrape retrieved two target elements" );
});
test( "Page - getHTML generation", function() {
var $document = window.document,
focument = (function(doc){
// load iframe into current doc
var iframe = document.createElement( "iframe" );
iframe.onload = function() {
// iframe doc for butter page faking
return iframe.contentDocument;
}
iframe.src = "../../templates/test.html";
document.body.appendChild( iframe );
}($document));
function swapDoc(){
window.document = focument;
}
function restoreDoc(){
window.document = $document;
}
swapDoc();
console.log(window.document.documentElement.innerHTML);
var html = _page.getHTML();
console.log(html);
restoreDoc();
});
});
})(window, document, Butter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment