GithubHelp home page GithubHelp logo

jeffwatkins / jasmine-dom Goto Github PK

View Code? Open in Web Editor NEW
60.0 60.0 9.0 18 KB

An add-on for the Jasmine Javascript test framework

Home Page: http://github.com/jeffwatkins/jasmine-dom

License: MIT License

JavaScript 95.86% HTML 4.14%

jasmine-dom's People

Contributors

jeffwatkins avatar mortonfox avatar xiongchiamiov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jasmine-dom's Issues

Array.prototype.indexOf not supported on IE8

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.

loadFixture doesn't work in Chrome when use file:///... URL.

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.

exception throw when using jasmine-maven-plugin

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

Using jasmine-dom with Karma

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...

fixtures: document.body is undefined when using Jasmine 1.2

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)

loadFixtures does not wait for async call

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);
  },

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.