Cordoba + Angular: how to check?

I recently started cheating on Cordoba for a mobile application. At the moment, the code base is quite small. I also used AngularJS to control my javascript. Now that I have reached a stable state, I would like to learn how to unit test the code I just wrote. The fact is that I do not find a useful resource for the couple. Angular offers either Karma (unit) or Protractor (scripts), but it’s difficult for me to download them using the Cordova application, since it should not run inside the browser, but in some kind of container where the cordova can be downloaded. Are there already good test approaches in the open source market associated with developing test-based hybrid applications?

+4
source share
4 answers

I think the right approach would be to get cordova.mocks.jsinvolved in tests that would mock cord dependencies. And then, as usual, turn it off.

0
source

You can use the "phonegap server", even if you use a cordova, you can also run on the device cordova run <platform> --device.

You can track problems at the CLI output of both methods.

0
source

, , .

Karma Protractor , ( cordova cordova), if

Ie if (window.cordova && cordova.plugins.thePluginExample) { /* Code that uses plugins [...] */ }

0
source

To help others who come here with the same question as me, ...

You probably don't need to boot from Cordova. Use mocks as stand-ins.

Since Cordova joins window, you can write your application code to enter $windowand mock the corridor with a standard mockery.

Example with mocha/ chai:

/**
 * Test case for AngularJS module that does something when platform = 'ios'
 */
describe('platform = "ios"', function() {

  var $window;
  beforeEach('inject', inject(function(_$window_) {
    $window = _$window_;

    $window.cordova = {
      platformId: 'ios',
    }
  }));

  it('verifies cordova mock platform = "ios"', function() {
    expect($window.cordova.platformId).to.equal('ios');
  });

  it('does something', function() {
    // ...
  });

});
0
source

Source: https://habr.com/ru/post/1541677/


All Articles