Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript JsTestDriver Jasmine & Jasmine-jquery

I have lots of Jasmine unit tests, that are running unit tests for Javascripts code. They are using Jasmine-jquery plugin to do DOM manipulation. they use loadFixture, to load fixtures of HTML

I tried to automate those unit tests, using JsTestDriver, with JasmineAdapter But all tests involve DOM-jquery manipulation are not passing? Is there something wrong with that? Is there a way to use Jasmine-jquery with JsTestDriver?

like image 889
Ghassan Karwchan Avatar asked Sep 19 '11 20:09

Ghassan Karwchan


2 Answers

I will answer myself because I found a solution for this problem. The problem was Jasmine-Jquery is using ajax to load the html fixture, and it uses a relative path, assuming the html fixtures are located in somewhere relative to the HTML container that is running Jasmine tests. but because JsTestDriver is loading the tests inside its own "space", so we have to change the location, where Jasmine-Jquery looks for those html fixtures, and make JsTestDriver load them.

so the solution is as follows:

JsTestDriver has the ability to load static html files. in config file add the following:

Serve: - for example: Serve: - fixtures*.html

now you can access those with the following format http:localhost:9876/test/fixtures/... you let Jasmine-jquery knows to load the fixtures from this location.

and voila, you will have your tests working again.

like image 171
Ghassan Karwchan Avatar answered Oct 22 '22 13:10

Ghassan Karwchan


Just to clarify a bit the previous posting.

If in your jsTestDriver config file you have:

serve:

spec/fixtures/*_fixture.html

Then, you need to override your test suite with

jasmine.getFixtures().fixturesPath = '/test/spec/fixtures';

Which is basically /test/ + whatever path you declare in the serve section in your jsTestDriver config file.

like image 33
Monica Avatar answered Oct 22 '22 11:10

Monica