I am using Grunt.js & Jasmine to do automated testing. One of my tests is supposed to check that a script has correctly created and appended an HTML node.
it('should create <div></div>', function() {
var element = document.getElementById("myElement");
expect(element.constructor()).toEqual(HTMLDivElement);
});
But when I run the test I just get an error back.
TypeError: 'null' is not an object (evaluating 'document.body.appendChild') in file:///foo.js (line 14) (1)
gruntfile.js:
jasmine : {
myTest: {
src: '../js/*.js',
options: {
specs:['tests/*.js'],
display: 'full',
summary: true,
junit: {
path: 'logs',
consolidate: true
}
}
}
}
package.json (partial):
"devDependencies": {
"grunt": "~0.4.2",
"grunt-jslint": "~1.1.8",
"grunt-jsdoc": "~0.5.4",
"grunt-contrib-jasmine": "~0.6.3",
"phantomjs": "1.8.2-0"
}