Skip to content

Commit 92dfc6c

Browse files
committed
chore(tests): add tests to increase coverage on login, plugin and resources.
1 parent 1b461af commit 92dfc6c

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

spec/tasks/login.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,26 @@ describe('login command', function() {
156156
done();
157157
});
158158
});
159+
160+
it('should ask for email and password and eject an error if error', function(done) {
161+
var processArguments = ['node', 'ionic', 'login'];
162+
var rawCliArguments = processArguments.slice(2);
163+
var argv = optimist(rawCliArguments).argv;
164+
var error = 'error logging in';
165+
166+
spyOn(log, 'info');
167+
spyOn(prompt, 'start');
168+
spyOn(prompt, 'get').andCallFake(function(schema, callback) {
169+
callback(error);
170+
});
171+
172+
var promptForLogin = login.__get__('promptForLogin');
173+
174+
promptForLogin(argv).catch(function(error) {
175+
expect(prompt.get).toHaveBeenCalled();
176+
expect(error).toEqual(error);
177+
done();
178+
});
179+
});
159180
});
160181
});

spec/tasks/plugin.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,24 @@ describe('plugin command', function() {
111111
});
112112
});
113113

114+
it('should add array of variables', function(done) {
115+
var processArguments = ['node', 'ionic', 'plugin', 'add', 'thing', '--variable', 'hello', '--variable', 'man'];
116+
var rawCliArguments = processArguments.slice(2);
117+
var argv = optimist(rawCliArguments).argv;
118+
119+
spyOn(State, 'savePlugin');
120+
spyOn(State, 'removePlugin');
121+
spyOn(cordovaUtils, 'execCordovaCommand').andReturn(Q(0));
122+
123+
plugin.run(null, argv, rawCliArguments).then(function() {
124+
expect(cordovaUtils.execCordovaCommand).toHaveBeenCalledWith(
125+
['plugin', 'add', 'thing', '--variable', 'hello', '--variable', 'man']);
126+
expect(State.savePlugin).toHaveBeenCalledWith(appDirectory, 'thing', ['hello', 'man']);
127+
expect(State.removePlugin).not.toHaveBeenCalled();
128+
done();
129+
});
130+
});
131+
114132
it('should add plugins', function(done) {
115133
var processArguments = ['node', 'ionic', 'plugin', 'add', 'thing', '--variable', 'hello'];
116134
var rawCliArguments = processArguments.slice(2);

spec/tasks/resources.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ describe('resources command', function() {
6565
});
6666
});
6767

68+
it('should fail if applib generate fails and not log error if not instanceof Error', function(done) {
69+
var processArguments = ['node', 'ionic', 'resources'];
70+
var rawCliArguments = processArguments.slice(2);
71+
var argv = optimist(rawCliArguments).argv;
72+
73+
var error = 'an error occurred';
74+
spyOn(process, 'cwd').andReturn('/current/directory');
75+
spyOn(Project, 'load');
76+
spyOn(IonicResources, 'generate').andReturn(Q.reject(error));
77+
spyOn(appLibUtils, 'fail');
78+
79+
// Expect failure
80+
resources.run(null, argv, rawCliArguments).then(function() {
81+
expect(appLibUtils.fail).not.toHaveBeenCalled();
82+
done();
83+
});
84+
});
85+
6886
it('should pass platforms on to the applib generate', function(done) {
6987
var processArguments = ['node', 'ionic', 'resources', '--icon'];
7088
var rawCliArguments = processArguments.slice(2);

0 commit comments

Comments
 (0)