-
-
Save humphd/3006865 to your computer and use it in GitHub Desktop.
Page Tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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 ); | |
var $document = document | |
// Wait to start our tests | |
stop(); | |
var focument; | |
function startTests(){ | |
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() { | |
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(); | |
}); | |
} | |
// load iframe into current doc | |
var iframe = document.createElement( "iframe" ); | |
iframe.onload = function() { | |
// iframe doc for butter page faking | |
focument = iframe.contentDocument; | |
start(); | |
startTests(); | |
} | |
iframe.src = "../../templates/test.html"; | |
document.body.appendChild( iframe ); | |
}); | |
})(window, document, Butter); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment