Question

I'm having a hard time getting JSTD to load a fixture HTML file.

My directory structure is:

 localhost/JsTestDriver.conf
 localhost/JsTestDriver.jar
 localhost/js/App.js
 localhost/js/App.test.js
 localhost/fixtures/index.html

My conf file says:

server: http://localhost:4224

serve:

- fixtures/*.html

load: 

- http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js
- jasmine/lib/jasmine-1.1.0/jasmine.js
- jasmine/jasmine-jquery-1.3.1.js
- jasmine/jasmine-jstd.js
- js/App.js

test: 

- js/App.test.js

My test is:

describe("App", function(){

    beforeEach(function(){
        jasmine.getFixtures().fixturesPath = 'fixtures';
        loadFixtures('index.html'); **//THIS LINE CAUSES IT TO FAIL**
    });

    describe("When App is loaded", function(){

        it('should have a window object', function(){
            expect(window).not.toBe(null);
        });

    });

});

And my console output is:

enter image description here

(link to full-size image)

I looked at this question but it didn't help me figure it out. The weird thing is, when I comment out the

loadFixtures('index.html');

line, the test passes.

Any ideas?

Was it helpful?

Solution

Okay -- figured it out. JsTestDriver prepends "test" to the path to your fixtures.

Also, jasmine-jquery gets fixtures using ajax.

Thus, these steps finally worked for me:

In jsTestDriver.conf:

serve:
 - trunk/wwwroot/fixtures/*.html

load:

  - trunk/wwwroot/js/libs/jquery-1.7.1.min.js 
  - jstd/jasmine/standalone-1.2.0/lib/jasmine-1.2.0/jasmine.js
  - jstd/jasmine-jstd-adapter/src/JasmineAdapter.js
  - jstd/jasmine-jquery/lib/jasmine-jquery.js

  - trunk/wwwroot/js/main.js

test:

  - trunk/wwwroot/js/main.test.js

In my test file:

describe("main", function(){

    beforeEach(function(){
        jasmine.getFixtures().fixturesPath = '/test/trunk/wwwroot/fixtures';
        jasmine.getFixtures().load('main.html');
    });

    describe("when main.js is loaded", function(){

        it('should have a div', function(){
            expect($('div').length).toBe(1); 
        });

    });

});

Note that the beforeEach() call uses an absolute URL to the HTML fixture.

OTHER TIPS

Try changing the fixture path to:

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

I get different, but similarly weird errors otherwise.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top