You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by au...@apache.org on 2017/08/11 20:15:10 UTC
cordova-lib git commit: CB-12361 : added tests for plugin/index.js
Repository: cordova-lib
Updated Branches:
refs/heads/master 9cdc0f2b1 -> acbd9e754
CB-12361 : added tests for plugin/index.js
Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/acbd9e75
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/acbd9e75
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/acbd9e75
Branch: refs/heads/master
Commit: acbd9e7547ddb0f2d632031535510e8705c08033
Parents: 9cdc0f2
Author: Audrey So <au...@apache.org>
Authored: Wed Jul 26 11:36:21 2017 -0700
Committer: Audrey So <au...@apache.org>
Committed: Fri Aug 11 13:07:52 2017 -0700
----------------------------------------------------------------------
spec/cordova/plugin/index.spec.js | 124 +++++++++++++++++++++++++++++----
1 file changed, 110 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/acbd9e75/spec/cordova/plugin/index.spec.js
----------------------------------------------------------------------
diff --git a/spec/cordova/plugin/index.spec.js b/spec/cordova/plugin/index.spec.js
index 1eea9b5..3cffa5c 100644
--- a/spec/cordova/plugin/index.spec.js
+++ b/spec/cordova/plugin/index.spec.js
@@ -27,14 +27,13 @@ var cordova_util = require('../../../src/cordova/util');
describe('cordova/plugin', function () {
var projectRoot = '/some/path';
var hook_mock = function () {};
- var hook_revert_mock;
+ var hook_revert_mock; // eslint-disable-line no-unused-vars
+
beforeEach(function () {
- hook_revert_mock = plugin.__set__('HooksRunner', hook_mock);
spyOn(cordova_util, 'cdProjectRoot').and.returnValue(projectRoot);
+ hook_revert_mock = plugin.__set__('HooksRunner', hook_mock);
});
- afterEach(function () {
- hook_revert_mock();
- });
+
describe('error conditions', function () {
// TODO: what about search cmd?
it('should require at least one target for add and rm commands', function (done) {
@@ -45,17 +44,114 @@ describe('cordova/plugin', function () {
}).done(done);
});
});
+
describe('handling/massaging of parameters', function () {
- it('should be able to handle an array of targets');
- it('should be able to handle a single string as a target');
- it('should transform targets that start with a dash into options');
- it('should also include targets into a plugins property on options');
+ var cmd = 'add';
+ beforeEach(function () {
+ spyOn(plugin, cmd).and.returnValue(true);
+ });
+
+ it('should be able to handle an array of platform targets', function (done) {
+ var targets = ['plugin1', 'plugin2', 'plugin3'];
+ plugin(cmd, targets)
+ .then(function () {
+ expect(plugin[cmd]).toHaveBeenCalledWith(projectRoot, jasmine.any(Object), Object({ options: [ ], plugins: [ 'plugin1', 'plugin2', 'plugin3' ] }));
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
+
+ it('should be able to handle a single string as a target', function (done) {
+ var targets = 'plugin1';
+ plugin(cmd, targets)
+ .then(function () {
+ expect(plugin[cmd]).toHaveBeenCalledWith(projectRoot, jasmine.any(Object), Object({ options: [ ], plugins: [ 'plugin1' ] }));
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
+
+ it('should transform targets that start with a dash into options', function (done) {
+ var targets = '-plugin1';
+ plugin(cmd, targets)
+ .then(function () {
+ expect(plugin[cmd]).toHaveBeenCalledWith(projectRoot, jasmine.any(Object), Object({ options: [ '-plugin1' ], plugins: [ ] }));
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
+
+ it('should also include targets into a plugins property on options', function (done) {
+ var options = {save: true};
+ var targets = 'plugin1';
+ plugin(cmd, targets, options)
+ .then(function () {
+ expect(plugin[cmd]).toHaveBeenCalledWith(projectRoot, jasmine.any(Object), Object({ save: true, options: [ ], plugins: [ 'plugin1' ] }));
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
});
+
describe('happy path', function () {
- it('should direct "add" command to the "add" submodule');
- it('should direct "rm" and "remove" commands to the "remove" submodule');
- it('should direct "search" command to the "search" submodule');
- it('should direct "save" command to the "save" submodule');
- it('should direct "list", all other commands and no command at all to the "list" submodule');
+
+ it('should direct "add" command to the "add" submodule', function (done) {
+ spyOn(plugin, 'add').and.returnValue(true);
+ plugin('add', ['cordova-plugin-splashscreen'])
+ .then(function () {
+ expect(plugin.add).toHaveBeenCalled();
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
+
+ it('should direct "rm" and "remove" commands to the "remove" submodule', function (done) {
+ spyOn(plugin, 'remove').and.returnValue(true);
+ plugin('remove', ['cordova-plugin-splashscreen'])
+ .then(function () {
+ expect(plugin.remove).toHaveBeenCalled();
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
+
+ xit('should direct "search" command to the "search" submodule', function (done) {
+ spyOn(plugin, 'search').and.returnValue(true);
+ plugin('search')
+ .then(function () {
+ expect(plugin.search).toHaveBeenCalled();
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
+
+ it('should direct "save" command to the "save" submodule', function (done) {
+ spyOn(plugin, 'save').and.returnValue(true);
+ plugin('save')
+ .then(function () {
+ expect(plugin.save).toHaveBeenCalled();
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
+
+ it('should direct "list", all other commands and no command at all to the "list" submodule', function (done) {
+ spyOn(plugin, 'list').and.returnValue(true);
+ plugin('list')
+ .then(function () {
+ expect(plugin.list).toHaveBeenCalled();
+ }).fail(function (e) {
+ expect(e).toBeUndefined();
+ fail('did not expect fail handler to be invoked');
+ }).done(done);
+ });
});
});
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org