create.js OnSubmit() unit test

This commit is contained in:
Carlos 2017-08-31 19:40:22 +02:00
parent c2e0a081e2
commit 3fd0a4f49d
1 changed files with 9 additions and 20 deletions

View File

@ -15,15 +15,8 @@ describe('Component vnClientCreate', () => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
$state = _$state_;
$scope.watcher = {
submit: () => {
return {
then: callback => {
callback({data: {id: '1234'}});
}
};
}
};
let submit = jasmine.createSpy('submit').and.returnValue(Promise.resolve({data: {id: '1234'}}));
$scope.watcher = {submit};
}));
it('should define and set scope, state and client properties', function() {
@ -34,16 +27,12 @@ describe('Component vnClientCreate', () => {
});
describe('onSubmit()', () => {
// spec broken due to callback acting a bit weirdo.
// it(`should call submit() on the watcher then expect a callback`, done => {
// let controller = $componentController('vnClientCreate', {$scope: $scope});
// spyOn($state, 'go').and.callFake(json => {
// return 1001;
// });
// controller.onSubmit();
// expect(controller.$.watcher.submit).toHaveBeenCalled();
// expect(controller.$state.go).toHaveBeenCalled();
// });
it(`should call submit() on the watcher then expect a callback`, done => {
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'});
});
});
});