jasmine-jquery won't load any fixture
Asked Answered
I

1

7

I am using karma + jasmine + jquery + jasmine-jquery I have several pure js unit tests and now it's time to move on to write some html dependent tests. I tried jasmine-jquery and its loadFixtures, but no matter what I try I am still getting an errors without any useful message.

I created simple project to test things in isolation, here is my setup:

.
├── karma.conf.js
├── package.json
├── spec
│   └── javascripts
│       └── fixtures
│           └── simple.test.html
└── src
    └── test
        └── js
            └── simple.test.js

package.json

{
  "dependencies": {
    "karma": "0.12.31",
    "jasmine": "2.1.1",
    "karma-jasmine": "0.3.5",
    "jasmine-jquery": "2.0.6",
    "karma-jasmine-jquery": "0.1.1",
    "karma-teamcity-reporter": "0.1.2"
  },
  "devDependencies": {
    "karma-chrome-launcher": "~0.1.7",
    "karma-firefox-launcher": "~0.1.4"
  }
}

spec/javascripts/fixtures/simple.test.html

<body>
    Test
</body>

src/test/js/simple.test.js

describe('simple', function () {
    beforeEach(function () {
        loadFixtures('simple.test.html');
    });

    it('test', function () {
        expect(true).toBeTruthy();
    });
});

I am getting this error

Chrome 27.0.1453 (Linux) simple test FAILED
    Error: Fixture could not be loaded: spec/javascripts/fixtures/simple.test.html (status: error, message: undefined)
        at Object.<anonymous> (/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:133:17)
        at fire (/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jqueryForJasmineJqueryPlugin.js:3094:30)
        at Object.self.add (/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jqueryForJasmineJqueryPlugin.js:3140:7)
        at jasmine.Fixtures.loadFixtureIntoCache_ (/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:132:10)
        at jasmine.Fixtures.getFixtureHtml_ (/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:115:12)
        at jasmine.Fixtures.read (/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:77:28)
        at jasmine.Fixtures.load (/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:65:37)
        at jasmine.Fixtures.proxyCallTo_ (/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:161:29)
        at window.loadFixtures (/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:765:27)


Firefox 24.0.0 (Linux) simple test FAILED
    Error: Fixture could not be loaded: spec/javascripts/fixtures/simple.test.html (status: error, message: undefined) in /tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js (line 133)
    jasmine.Fixtures.prototype.loadFixtureIntoCache_/request<@/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:133
    jQuery.Callbacks/fire@/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jqueryForJasmineJqueryPlugin.js:3094
    jQuery.Callbacks/self.add@/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jqueryForJasmineJqueryPlugin.js:3140
    jasmine.Fixtures.prototype.loadFixtureIntoCache_@/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:132
    jasmine.Fixtures.prototype.getFixtureHtml_@/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:115
    jasmine.Fixtures.prototype.read@/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:77
    jasmine.Fixtures.prototype.load@/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:65
    jasmine.Fixtures.prototype.proxyCallTo_@/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:161
    window.loadFixtures@/tmp/zkurv/node_modules/karma-jasmine-jquery/lib/jasmine-jquery.js:765
    @/tmp/zkurv/src/test/js/simple.test.js:3

Any help?

Infernal answered 17/2, 2015 at 13:17 Comment(0)
O
13

The fixtures need to be defined in the files list in karma.conf.js. Karma serves the files under the /base directory: http://karma-runner.github.io/0.8/plus/RequireJS.html.

I have setup the project same way you did, defined fixtures in karma.conf.js and I can manually access the fixture through the browser launched by Karma: http://localhost:9876/base/spec/javascripts/fixtures/simple.test.html.

The default fixtures path needs to be setup in Jasmine:

jasmine.getFixtures().fixturesPath = 'base/spec/javascripts/fixtures';
loadFixtures('simple.test.html');
Oglethorpe answered 18/2, 2015 at 17:41 Comment(1)
This is perhaps unrelated but I haven't been able to find any help on it specifically (or don't properly know how to look,) and I would really appreciate some help. I have posted a question but have received no answers. I have an ASP.NET app using aspx pages with some stuff 'runat server'. Is it possible to test my UI using jasmine-jquery in such a scenario? what tools would I need in addition to j-j? Do I need to have karma? Anything else?Zaporozhye

© 2022 - 2024 — McMap. All rights reserved.