So I'm trying to set up a mocha test with jsdom and after many attempts at debugging I narrowed down the problem to jsdom executing absolute URL scripts (e.g. http://ift.tt/16ygW8q) but not relative URL scripts (e.g. js/script.js).
My test.js is below:
var assert = require("assert");
var fs = require('fs');
var jsdom = require("jsdom");
describe('Foo Test', function(){
it('Foo Check', function(done){
this.timeout(5000);
jsdom.env({
html: fs.readFileSync('index.htm')
,features: {
FetchExternalResources: ["script"]
,ProcessExternalResources: ["script"]
}
,done: function(errors, window){
if(errors != null) console.log('Errors', errors);
var $ = window.$; // $ is defined
var foo = window.foo; //foo is undefined
assert(foo);
done();
}
});
});
});
And the error: Uncaught AssertionError: undefined == true
The htm:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Foo</title>
<script src="http://ift.tt/13jmVM7"></script>
<script src="js/script.js"></script>
</head>
<body>
</body>
</html>
script.js:
var foo = true;
Aucun commentaire:
Enregistrer un commentaire