@@ -70,14 +70,13 @@ describe('build command', function() {
7070 it ( 'should fail if the system is not Mac and the platform is iOS' , function ( done ) {
7171 spyOn ( os , 'platform' ) . andReturn ( 'windows' ) ;
7272
73- build . run ( null , argv , rawCliArguments ) . catch ( function ( error ) {
74- expect ( error ) . toEqual ( '✗ You cannot run iOS unless you are on Mac OSX.' ) ;
73+ build . run ( null , argv , rawCliArguments ) . then ( function ( ) {
74+ expect ( log . error ) . toHaveBeenCalledWith ( '✗ You cannot run iOS unless you are on Mac OSX.' ) ;
7575 done ( ) ;
7676 } ) ;
7777 } ) ;
7878 } ) ;
7979
80-
8180 describe ( 'cordova platform and plugin checks' , function ( ) {
8281
8382 var appDirectory = '/ionic/app/path' ;
@@ -91,11 +90,11 @@ describe('build command', function() {
9190
9291 spyOn ( cordovaUtils , 'installPlatform' ) . andReturn ( Q ( true ) ) ;
9392 spyOn ( cordovaUtils , 'installPlugins' ) . andReturn ( Q ( true ) ) ;
94- spyOn ( cordovaUtils , 'execCordovaCommand' ) . andReturn ( Q ( 0 ) ) ;
9593 } ) ;
9694
9795 it ( 'should try to install the cordova platform if it is not installed' , function ( done ) {
9896 spyOn ( cordovaUtils , 'isPlatformInstalled' ) . andReturn ( false ) ;
97+ spyOn ( cordovaUtils , 'execCordovaCommand' ) . andReturn ( Q ( 0 ) ) ;
9998
10099 build . run ( null , argv , rawCliArguments ) . then ( function ( ) {
101100 expect ( cordovaUtils . installPlatform ) . toHaveBeenCalledWith ( 'ios' ) ;
@@ -106,6 +105,7 @@ describe('build command', function() {
106105
107106 it ( 'should not try to install the cordova platform if it is installed' , function ( done ) {
108107 spyOn ( cordovaUtils , 'isPlatformInstalled' ) . andReturn ( true ) ;
108+ spyOn ( cordovaUtils , 'execCordovaCommand' ) . andReturn ( Q ( 0 ) ) ;
109109
110110 build . run ( null , argv , rawCliArguments ) . then ( function ( ) {
111111 expect ( cordovaUtils . installPlatform ) . not . toHaveBeenCalledWith ( ) ;
@@ -116,6 +116,7 @@ describe('build command', function() {
116116 it ( 'should install plugins if they are not installed' , function ( done ) {
117117 spyOn ( cordovaUtils , 'isPlatformInstalled' ) . andReturn ( true ) ;
118118 spyOn ( cordovaUtils , 'arePluginsInstalled' ) . andReturn ( false ) ;
119+ spyOn ( cordovaUtils , 'execCordovaCommand' ) . andReturn ( Q ( 0 ) ) ;
119120
120121 build . run ( null , argv , rawCliArguments ) . then ( function ( ) {
121122 expect ( cordovaUtils . arePluginsInstalled ) . toHaveBeenCalledWith ( appDirectory ) ;
@@ -127,12 +128,37 @@ describe('build command', function() {
127128 it ( 'should not install plugins if they are installed' , function ( done ) {
128129 spyOn ( cordovaUtils , 'isPlatformInstalled' ) . andReturn ( true ) ;
129130 spyOn ( cordovaUtils , 'arePluginsInstalled' ) . andReturn ( true ) ;
131+ spyOn ( cordovaUtils , 'execCordovaCommand' ) . andReturn ( Q ( 0 ) ) ;
130132
131133 build . run ( null , argv , rawCliArguments ) . then ( function ( ) {
132134 expect ( cordovaUtils . arePluginsInstalled ) . toHaveBeenCalledWith ( appDirectory ) ;
133135 expect ( cordovaUtils . installPlugins ) . not . toHaveBeenCalledWith ( ) ;
134136 done ( ) ;
135137 } ) ;
136138 } ) ;
139+
140+ it ( 'should fail if any functions throw' , function ( done ) {
141+ var error = new Error ( 'error occurred' ) ;
142+ spyOn ( cordovaUtils , 'isPlatformInstalled' ) . andReturn ( true ) ;
143+ spyOn ( cordovaUtils , 'arePluginsInstalled' ) . andReturn ( true ) ;
144+ spyOn ( cordovaUtils , 'execCordovaCommand' ) . andReturn ( Q . reject ( error ) ) ;
145+
146+ build . run ( { } , argv , rawCliArguments ) . then ( function ( ) {
147+ expect ( log . error ) . toHaveBeenCalledWith ( error ) ;
148+ done ( ) ;
149+ } ) ;
150+ } ) ;
151+
152+ it ( 'should fail if any functions throw and not log if not an instance of an Error' , function ( done ) {
153+ var error = 1 ;
154+ spyOn ( cordovaUtils , 'isPlatformInstalled' ) . andReturn ( true ) ;
155+ spyOn ( cordovaUtils , 'arePluginsInstalled' ) . andReturn ( true ) ;
156+ spyOn ( cordovaUtils , 'execCordovaCommand' ) . andReturn ( Q . reject ( error ) ) ;
157+
158+ build . run ( { } , argv , rawCliArguments ) . then ( function ( ) {
159+ expect ( log . error ) . not . toHaveBeenCalled ( ) ;
160+ done ( ) ;
161+ } ) ;
162+ } ) ;
137163 } ) ;
138164} ) ;
0 commit comments