Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Karma Jasmine Cordova plugins

I am attempting to understand karma/jasmine with Cordova mobile app integration.

However my problem is that I would like to test for example WifiWizard (cordova plugin) on my unit test.

e.g:

describe('WifiWizard', () => {
    it('Is defined', () => {
        expect(WifiWizard).toBeDefined();
    });

    it('Not Empty Object', () => {
       expect(WifiWizard).not.toEqual({});
    });
});

But I require cordova.js to be included, alas cordova.js is being included in the index.html file in my www root folder.

Any help would be greatly appreciated.

like image 883
Joseph Briggs Avatar asked Oct 23 '25 18:10

Joseph Briggs


1 Answers

WifiWizard is a plugin hence it contains native code as well as Javascript. The only way to test this would be either to stub out the plugin's JS API to return mock responses, or to test the actual plugin on an real mobile device (as opposed in a browser).

You can actually do this using Appium in conjunction with wd-bridge in order to remotely control the device. I've successfully done this, using Protractor tests to remotely drive Android and iOS devices running a Cordova-based app. Protractor is more suitable for this kind of end-to-end testing than Karma. There's a useful blog post that may help you to set up the test environment should you decide to go down this route.

like image 74
DaveAlden Avatar answered Oct 26 '25 20:10

DaveAlden