From 62c15fbafa61842d1890507997b33fc9d2feb3b8 Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 4 Sep 2017 12:46:19 +0200 Subject: [PATCH] create client onSubmit callback tested --- client/client/src/create/create.spec.js | 27 +++++++++++++++---------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/client/client/src/create/create.spec.js b/client/client/src/create/create.spec.js index 028dabfe7..360af052a 100644 --- a/client/client/src/create/create.spec.js +++ b/client/client/src/create/create.spec.js @@ -13,25 +13,30 @@ describe('Component vnClientCreate', () => { $componentController = _$componentController_; $scope = $rootScope.$new(); $state = _$state_; - let submit = jasmine.createSpy('submit').and.returnValue(Promise.resolve({data: {id: '1234'}})); - $scope.watcher = {submit}; + $scope.watcher = { + submit: () => { + return { + then: callback => { + callback({data: {id: '1234'}}); + } + }; + } + }; })); it('should define and set scope, state and client properties', function() { - let controller = $componentController('vnClientCreate', {$scope: $scope, $state: $state}); + let controller = $componentController('vnClientCreate', {$scope: $scope}); expect(controller.$).toBe($scope); expect(controller.$state).toBe($state); expect(controller.client.active).toBe(true); }); describe('onSubmit()', () => { - // promise isn't callig go function, needs fixing. - // it(`should call submit() on the watcher then expect a callback`, () => { - // let controller = $componentController('vnClientCreate', {$scope: $scope}); - // spyOn($state, 'go'); - // controller.onSubmit(); - // expect(controller.$.watcher.submit).toHaveBeenCalled(); - // expect(controller.$state.go).toHaveBeenCalledWith('clientCard.basicData', {id: '1234'}); - // }); + it(`should call submit() on the watcher then expect a callback`, () => { + let controller = $componentController('vnClientCreate', {$scope: $scope}); + spyOn($state, 'go'); + controller.onSubmit(); + expect(controller.$state.go).toHaveBeenCalledWith('clientCard.basicData', {id: '1234'}); + }); }); });