UNPKG

@darkobits/formation

Version:
71 lines (52 loc) 2.15 kB
'use strict'; var _unity = require('@darkobits/unity'); var _constants = require('../../etc/constants'); var _index = require('../../index'); var _index2 = _interopRequireDefault(_index); var _ConfigurableValidator = require('./ConfigurableValidator'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } describe('ConfigurableValidator', function () { describe('creating configurable validators', function () { it('should throw an error if not provided a function', function () { expect(function () { return new _ConfigurableValidator.ConfigurableValidator(null); }).toThrow('expected validator to be of type Function'); }); it('should assign a bound copy of the provided function to itself', function () { function myValidator() {} var V = new _ConfigurableValidator.ConfigurableValidator(myValidator); expect(V.validator.name).toMatch('bound myValidator'); }); it('should assign the CONFIGURABLE_VALIDATOR value to itself', function () { var V = new _ConfigurableValidator.ConfigurableValidator(function () {}); expect(V[_constants.CONFIGURABLE_VALIDATOR]).toBe(true); }); }); describe('#configure', function () { var Form = void 0; var T = void 0; var V = void 0; beforeEach(function () { (0, _unity.module)(_index2.default); var wrapper = (0, _unity.compile)({ template: '<fm></fm>' }); Form = wrapper.controller('fm'); T = (0, _unity.directive)('fmInput', { template: '<fm-input></fm-input>', wrap: wrapper }); V = new _ConfigurableValidator.ConfigurableValidator(function () {}); V.configure(T.fmInput); }); it('should assign a reference to the form', function () { expect(V.form).toBe(Form); }); it('should assign a reference to the forms scope', function () { expect(V.scope.$id).toBeTruthy(); }); it('should assign a reference to the controls ngModel controller', function () { expect(V.ngModelCtrl).toEqual(T.fmInput[_constants.NG_MODEL_CTRL]); }); }); });