简体   繁体   中英

Jasmine test case in maven with requirejs

I want to use jasmine for unit testing javascript application. My application uses requirejs. I found Jasmine maven plugin

This plugin works great for non requirejs application. It also has requirejs template but i am unable to successfully run testcases with maven.

I have written sample test case as

 require(['models/MyModel'], function(GlobalSettingsModel) { //this code doesn't execute describe('Test description', function() { it('some test', function(done) { expect(1 + 2).toBe(4); //it doesn't throw error }); }); }); describe('Test description new', function() { require(['models/MyModel'], function(GlobalSettingsModel) { it('some test', function(done) { expect(1 + 2).toBe(4); //it doesn't throw error }); }); }); describe('Test description new', function() { it('some test', function(done) { expect(1 + 2).toBe(4); //it throw error }); }); 

If i wrap my testcase inside requirejs then maven won't execute code inside requirejs block. If i give non existent js file in requirejs(first line) then it throw error that file is not exist.

I have tried many ways to integrate jasmine(requirejs) with maven but unable to find any other plugin or any solution.

Instead of wrapping describe method in require block, i need to wrap describe in define block

 define(['model'], function(Model) { describe('Test description new', function() { it('some test', function(done) { expect(1 + 2).toBe(4); //it throw error }); }); }); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM