jeffwatkins / jasmine-dom Goto Github PK
View Code? Open in Web Editor NEWAn add-on for the Jasmine Javascript test framework
Home Page: http://github.com/jeffwatkins/jasmine-dom
License: MIT License
An add-on for the Jasmine Javascript test framework
Home Page: http://github.com/jeffwatkins/jasmine-dom
License: MIT License
I'm currently running some tests on IE8, and toHaveClass
matcher fails on IE8 because Array.prototype.indexOf
is undefined.
To work around this issue, I've patched the matcher to use regex:
toHaveClass: function(className)
{
var classes = jasmine.DOM.trim(this.actual.className);
return RegExp('(^| )' + className + '( |$)').test(classes);
},
The regex itself comes from here.
Setting an object's visibility to 'hidden' will still cause toBeVisible() to return true. Even though it takes up space on the page, it seems logical that adjusting the visible
attribute will change visiblity. ;)
The test contains only loadFixtures() call.
It works fine in Firefox but throws the following error in Chrome:
NETWORK_ERR: NETWORK_ERR: XMLHttpRequest Exception 101
I opened test runner using file:// URL
file:///.../runner.html
If it's possible, it would be great to have ability to run tests without web server in all browsers.
I am trying to use the jasmine-maven-plugin with the jasmine-dom testing addon.
When I add the jasmine-dom-matchers.js feature, I have found that the plugin fails the build with the following error.
com.gargoylesoftware.htmlunit.ScriptException: Error: Can't determine selector engine...
As the test passes when using a standard browser, this error is due to some missing feature in the htmlUnit engine.
I have traced the exception to the following code
jasmine.DOM.queryAll= (function(){
if ('undefined'!==typeof(Sizzle))
return Sizzle;
if ('undefined'!==typeof(Prototype))
return function(selector, node)
{
return Element.getElementsBySelector(node||document, selector);
};
if ('undefined'!==typeof(jQuery))
return function(selector, node)
{
var result= jQuery(selector, node);
var nodes= [];
var len= result.length;
for (var i=0; i<len; ++i)
nodes.push(result[i]);
return nodes;
};
if (document.querySelectorAll)
return function(selector, node)
{
if (!node)
node= document;
else if (node!==document)
selector = ['#', jasmine.DOM.assignId(node), ' ', selector].join('');
return jasmine.DOM.slice(node.querySelectorAll(selector));
};
throw new Error("Can't determine selector engine...");
})();
any ideas, workarounds?
Thanks
Richard
Are there any plans to package this as a node module useable as a Karma framework, much like jasmine-jquery has been packaged as karma-jasmine-jquery?
If not, would you know how to add jasmine-dom support to Karma? I've tried npm install jasmine-dom
, which gives me something I can require
in my karma.conf
file, but I can't access its features from inside my specs...
Maybe I am doing something wrong here, but I get an error in Jasmine 1.2:
TypeError: Cannot call method 'appendChild' of null
TypeError: Cannot call method 'appendChild' of null
at Object.jasmine.Fixtures._createContainer (http://localhost/git/ol3_bartvde/test/jasmine-dom-fixtures.js:137:19)
at Object.jasmine.Fixtures.load (http://localhost/git/ol3_bartvde/test/jasmine-dom-fixtures.js:77:10)
at Object.jasmine.Fixtures._proxyCallTo (http://localhost/git/ol3_bartvde/test/jasmine-dom-fixtures.js:172:29)
at loadFixtures (http://localhost/git/ol3_bartvde/test/jasmine-dom-fixtures.js:9:25)
at null.<anonymous> (http://localhost/git/ol3_bartvde/test/spec/ol/parser/ogc/wmscapabilities_v1_1_1.test.js:6:5)
at jasmine.Env.describe (http://localhost/git/ol3_bartvde/test/jasmine-1.2.0/jasmine.js:806:21)
at describe (http://localhost/git/ol3_bartvde/test/jasmine-1.2.0/jasmine.js:590:27)
at null.<anonymous> (http://localhost/git/ol3_bartvde/test/spec/ol/parser/ogc/wmscapabilities_v1_1_1.test.js:5:3)
at jasmine.Env.describe (http://localhost/git/ol3_bartvde/test/jasmine-1.2.0/jasmine.js:806:21)
at describe (http://localhost/git/ol3_bartvde/test/jasmine-1.2.0/jasmine.js:590:27)
I've tried Safari and Firefox
I'm using loadFixtures to load html for a jasmine spec.
Here is my spec
describe("example", function(){
it("has text when set using text method", function(){
loadFixtures("spec/fixtures/example.html");
var node = document.getElementById('validationDiv');
expect(node).toExist();
expect(document.getElementById("validationDiv")).toBeDefined();
expect(document.getElementById("validationDiv")).toExist();
document.getElementById("validationDiv").innerHTML = "hi there";
expect(document.getElementById("validationDiv").innerHTML).toEqual("hi there");
});
});
Here is my fixture
<div id="my-example-fixture">
<input type="text" id="text1"></input>
<input type="text" id="text2"></input>
<div id="validationDiv"></div>
</div>
In debugging the code, the loadFixtures method is returning to the test caller prior to the callback being handled in
_loadFixtureIntoCache: function(url)
{
var self= this;
var xhr= new jasmine.Fixtures.XHR();
xhr.open('GET', url, true);
xhr.onreadystatechange= function()
{
if (4!==xhr.readyState)
return;
var status= xhr.status; // <<<< This line is hit after the test has already failed
var succeeded= 0===status || (status>=200 && status<300) || 304==status;
if (!succeeded)
throw new Error('Failed to load resource: status=' + status + ' url=' + url);
self._fixturesCache[url]= xhr.responseText; // <<<< The expected html is returned as responseText
xhr.onreadystatechange= null;
xhr= null;
}
xhr.send(null);
},
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.