Jasmine compatibility with jQuery Mobile

I'm just in the middle of implementing some Jasmine tests for jQuery mobile that I'm working on, I encountered an error that I was able to track before adding the jQuery mobile library, the error is the following:

Jasmine.js:1769 TypeError: Cannot read property 'abort' of undefined. 

As soon as I remove the jQM dependency, the error will disappear.

This is my code:

 <!DOCTYPE html> <html> <head> <title>HTML5/Common/Tests</title> <!-- LOAD STYLES FIRST --> <link type="text/css" rel="stylesheet" href="libs/jasmine.css" media="screen"> <link type="text/css" rel="stylesheet" href="../../Common/libs/jquery.mobile-1.0.1.css" /> <!-- LOAD JASMINE LIBRARIES --> <script type="text/javascript" src="libs/jasmine.js"></script> <script type="text/javascript" src="libs/jasmine-html.js"></script> <!-- LOAD DEPENDENCIES --> <script type="text/javascript" src="../../Common/libs/jquery-1.7.1.min.js"></script> <script type="text/javascript" src="../../Common/libs/jquery.mobile-1.0.1.min.js"></script> <!-- LOAD CODE TO TEST --> <script type="text/javascript" src="../../Common/libs/myLib.js"></script> <!-- LOAD ACTUAL TESTS --> <script type="text/javascript"> describe("Suite 1", function() { it("Should be that 1 equals 0", function() { expect(0).toEqual(1); }); }); </script> </head> <body> <script type="text/javascript"> jasmine.getEnv().addReporter(new jasmine.TrivialReporter()); jasmine.getEnv().execute(); </script> </body> </html> 

I would prefer to use Jasmine for this application instead of qUnit , as I find it more flexible and easier to implement in CI and explain to BA and PM's .. however, after messing with this problem for several hours and some useless google searches , I still could not solve it, so I'm starting to consider the transition.

Before I do this, did anyone experience the same problem and find a solution for it?

Thanks and respect.

UPDATE March 20:

Ticket in github Jasmine project:

https://github.com/pivotal/jasmine/issues/204

+4
source share
2 answers

I had a jasmine test for jQuery mobile scripts using jasmine-jquery .

The trick is that you need to disable jQuery for mobile on DOMready because it will try to improve the html jasmine runner. You can do this with this script pasted into the head of the html runner file:

 <script type="text/javascript"> $(document).bind("mobileinit", function(){ $.mobile.autoInitializePage = false; }); </script> 

Then you need to activate the jquery mobile extension on the html inserted from your device (jasmine-jquery functionnality function):

 describe('my test', function(){ beforeEach(function() { loadFixtures("fixtures/MYFixture.html"); $("#jasmine-fixtures").attr("data-role","page").trigger("create"); } it( ... }); 
+9
source

Try disabling both automatic initialization and hash listening:

 <script type="text/javascript"> $(document).bind("mobileinit", function(){ $.mobile.autoInitializePage = false; $.mobile.hashListeningEnabled = false; }); </script> 

Then add the jqm page to the jasmine-jquery shortcut and initialize the page:

 beforeEach(function() { jasmine.getFixtures().set('<div data-role="page"></div>'); $.mobile.initializePage(); }); 
+1
source

Source: https://habr.com/ru/post/1402401/


All Articles