vormjs
Version:
Write your forms in JSON and HTML, use the same API.
64 lines (40 loc) • 1.35 kB
JavaScript
/*global describe, beforeEach,module,inject,angular,spyOn,it,expect,jasmine*/
describe('vormSubmit', function ( ) {
var element,
$rootScope,
formScope,
$compile;
beforeEach(module('vorm'));
beforeEach(inject([ '$rootScope', '$compile', function ( ) {
$rootScope = arguments[0];
$compile = arguments[1];
element = angular.element(`
<form vorm-form vorm-submit="handleSubmit($values)">
<input type="text" ng-model="values.name" name="name"/>
<input type="text" ng-model="values.age" name="age"/>
</form>
`);
formScope = $rootScope.$new();
formScope.handleSubmit = function ( ) {};
$compile(element)(formScope);
$rootScope.$digest();
}]));
describe('when submitted', function ( ) {
// it('should call the handler', function ( ) {
// spyOn(formScope, 'handleSubmit');
// element.triggerHandler('submit');
// expect(formScope.handleSubmit).toHaveBeenCalled();
// });
it('should call the handler with the correct values', function ( ) {
spyOn(formScope, 'handleSubmit');
formScope.values = {name: 'foo', age: 10 };
formScope.$digest();
element.triggerHandler('submit');
expect(formScope.handleSubmit)
.toHaveBeenCalledWith(jasmine.objectContaining({
name: 'foo',
age: 10
}));
});
});
});