Javascript JsTestDriver Jasmine & Jasmine-jquery
Asked Answered
F

3

5

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?

Fateful answered 19/9, 2011 at 20:3 Comment(0)
F
9

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.

Fateful answered 20/9, 2011 at 15:34 Comment(3)
I have my jar file running in my folder "jasmine" Inside there I have lib/jasmine-core/jasmine.js. i also have scripts/test.js and fixtures/text.html. I did Serve:- fixtures/*.html but I'm still getting panic errors with 'fixtures' '/fixtures' and other variations when setting jasmines fixturePath. Any ideas?Firmin
Ah I read Monica's answer and saw I needed to put /test/ in front. That solved it. The localhost example was throwing me off a bit since my server is not on localhost.Firmin
This doesn't seem to work for JsTestDriver-1.3.4-a.jar but i t does for JsTestDriver-1.3.4.b.jar on Windows.Cazzie
S
3

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.

Simferopol answered 1/11, 2011 at 21:51 Comment(0)
M
0

I just released an open source toolkit which will hopefully help others as much as it helps me. It is a composition of many open source tools which gives you a working requirejs backbone app out of the box.

It has a more elegant solution to this using the requirejs text plugin and the requirejs handlebars plugin.

It provides single commands to run: dev web server, jasmine single browser test runner, jasmine js-test-driver multi browser test runner, and concatenization/minification for JavaScript and CSS. It also outputs an unminified version of your app for production debugging, precompiles your handlebar templates, and supports internationalization. No setup is required. It just works.

http://github.com/davidjnelson/agilejs

Masry answered 16/2, 2013 at 19:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.