| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741 |
- var originalDefaultOptions = $.fn.bootstrapValidator.DEFAULT_OPTIONS;
- TestSuite = $.extend({}, TestSuite, {
- Event: {
- onEmailValid: function(e, data) {
- $('#msg').html('TestSuite.Event.onEmailValid() called, ' + data.field + ' is valid');
- },
- onEmailInvalid: function(e, data) {
- $('#msg').html('TestSuite.Event.onEmailInvalid() called, ' + data.field + ' is invalid');
- },
- onEmailStatus: function(e, data) {
- $('#status').html('TestSuite.Event.onEmailStatus() called; status = ' + data.status);
- },
- onFormValid: function(e) {
- $('#msg').html('TestSuite.Event.onFormValid() called, form ' + $(e.target).attr('id') + ' is valid');
- },
- onFormInvalid: function(e) {
- $('#msg').html('TestSuite.Event.onFormInvalid() called, form ' + $(e.target).attr('id') + ' is invalid');
- }
- }
- });
- // ---
- // Form events
- // ---
- function onFormValid(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' is valid');
- };
- function onFormInvalid(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' is invalid');
- };
- describe('event form attribute callback global', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm" data-bv-onsuccess="onFormValid" data-bv-onerror="onFormInvalid" >',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" required data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm').bootstrapValidator();
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('call data-bv-onsuccess', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('form eventForm is valid');
- });
- it('call data-bv-onerror', function() {
- this.$email.val('a@b@c@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('form eventForm is invalid');
- });
- });
- describe('event form attribute callback namespace', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm" data-bv-onsuccess="TestSuite.Event.onFormValid" data-bv-onerror="TestSuite.Event.onFormInvalid" >',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" required data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm').bootstrapValidator();
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('call data-bv-onsuccess', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('TestSuite.Event.onFormValid() called, form eventForm is valid');
- });
- it('call data-bv-onerror', function() {
- this.$email.val('just"not"right@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('TestSuite.Event.onFormInvalid() called, form eventForm is invalid');
- });
- });
- describe('event form trigger', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm')
- .bootstrapValidator()
- .on('success.form.bv', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered success.form.bv event');
- })
- .on('error.form.bv', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered error.form.bv event');
- });
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('trigger success.form.bv', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('form eventForm triggered success.form.bv event');
- });
- it('trigger error.form.bv', function() {
- this.$email.val('this is"not\\allowed@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('form eventForm triggered error.form.bv event');
- });
- });
- describe('event form programmatically', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm').bootstrapValidator({
- onSuccess: function(e) {
- $('#msg').html('onSuccess() called');
- },
- onError: function(e) {
- $('#msg').html('onError() called');
- }
- });
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('call onSuccess()', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('onSuccess() called');
- });
- it('call onError()', function() {
- this.$email.val('Abc.example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('onError() called');
- });
- });
- // ---
- // Field events
- // ---
- function onEmailValid(e, data) {
- $('#msg').html(data.field + ' is valid');
- };
- function onEmailInvalid(e, data) {
- $('#msg').html(data.field + ' is invalid');
- };
- function onEmailStatus(e, data) {
- $('#status').html(data.status);
- };
- describe('event field attribute callback global', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm">',
- '<div id="msg"></div>',
- '<div id="status"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress data-bv-onsuccess="onEmailValid" data-bv-onerror="onEmailInvalid" data-bv-onstatus="onEmailStatus" />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm').bootstrapValidator();
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('call data-bv-onsuccess', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('email is valid');
- expect($('#status').html()).toEqual(this.bv.STATUS_VALID);
- });
- it('call data-bv-onerror', function() {
- this.$email.val('A@b@c@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('email is invalid');
- expect($('#status').html()).toEqual(this.bv.STATUS_INVALID);
- });
- });
- describe('event field attribute callback namespace', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm">',
- '<div id="msg"></div>',
- '<div id="status"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress data-bv-onsuccess="TestSuite.Event.onEmailValid" data-bv-onerror="TestSuite.Event.onEmailInvalid" data-bv-onstatus="TestSuite.Event.onEmailStatus" />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm').bootstrapValidator();
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('call data-bv-onsuccess', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('TestSuite.Event.onEmailValid() called, email is valid');
- expect($('#status').html()).toEqual('TestSuite.Event.onEmailStatus() called; status = ' + this.bv.STATUS_VALID);
- });
- it('call data-bv-onerror', function() {
- this.$email.val('a"b(c)d,e:f;gi[j\\k]l@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('TestSuite.Event.onEmailInvalid() called, email is invalid');
- expect($('#status').html()).toEqual('TestSuite.Event.onEmailStatus() called; status = ' + this.bv.STATUS_INVALID);
- });
- });
- describe('event field trigger', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm')
- .bootstrapValidator()
- .on('success.field.bv', '[name="email"]', function(e, data) {
- $('#msg').html('triggered success.field.bv on ' + data.field);
- })
- .on('error.field.bv', '[name="email"]', function(e, data) {
- $('#msg').html('triggered error.field.bv on ' + data.field);
- });
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('trigger success.field.bv', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('triggered success.field.bv on email');
- });
- it('trigger error.field.bv', function() {
- this.$email.val('just"not"right@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('triggered error.field.bv on email');
- });
- });
- describe('event field programmatically', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm').bootstrapValidator({
- fields: {
- email: {
- onSuccess: function(e, data) {
- $('#msg').html('onSuccess() called');
- },
- onError: function(e, data) {
- $('#msg').html('onError() called');
- }
- }
- }
- });
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('call onSuccess()', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('onSuccess() called');
- });
- it('call onError()', function() {
- this.$email.val('this is"not\\allowed@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('onError() called');
- });
- });
- // ---
- // Modifying default events
- // ---
- describe('event form trigger with default events', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm1">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm1')
- .bootstrapValidator()
- .on('bv.form.success', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered bv.form.success event');
- })
- .on('success.form.bv', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered success.form.bv event');
- })
- .on('bv.form.error', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered bv.form.error event');
- })
- .on('error.form.bv', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered error.form.bv event');
- });
- this.bv = $('#eventForm1').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm1').bootstrapValidator('destroy').remove();
- });
- it('does not trigger bv.form.success', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).not.toEqual('form eventForm1 triggered bv.form.success event');
- });
- it('triggers success.form.bv', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('form eventForm1 triggered success.form.bv event');
- });
- it('does not trigger bv.form.error', function() {
- this.$email.val('A@b@c@example.com');
- this.bv.validate();
- expect($('#msg').html()).not.toEqual('form eventForm1 triggered bv.form.error event');
- });
- it('triggers error.form.bv', function() {
- this.$email.val('A@b@c@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('form eventForm1 triggered error.form.bv event');
- });
- });
- describe('event field trigger with default events', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm3">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm3')
- .bootstrapValidator()
- .on('success.field.bv', '[name="email"]', function(e, data) {
- $('#msg').html('triggered success.field.bv on ' + data.field);
- })
- .on('error.field.bv', '[name="email"]', function(e, data) {
- $('#msg').html('triggered error.field.bv on ' + data.field);
- })
- .on('bv.field.success', '[name="email"]', function(e, data) {
- $('#msg').html('triggered bv.field.success on ' + data.field);
- })
- .on('bv.field.error', '[name="email"]', function(e, data) {
- $('#msg').html('triggered bv.field.error on ' + data.field);
- });
- this.bv = $('#eventForm3').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm3').bootstrapValidator('destroy').remove();
- });
- it('triggers success.field.bv', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('triggered success.field.bv on email');
- });
- it('does not trigger bv.field.success', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).not.toEqual('triggered bv.field.success on email');
- });
- it('does not trigger error.field.bv', function() {
- this.$email.val('just"not"right@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('triggered error.field.bv on email');
- });
- it('triggers bv.field.error', function() {
- this.$email.val('just"not"right@example.com');
- this.bv.validate();
- expect($('#msg').html()).not.toEqual('triggered bv.field.error on email');
- });
- });
- describe('event form trigger with events changed', function() {
- var defaultOptions = $.fn.bootstrapValidator.DEFAULT_OPTIONS;
- beforeEach(function() {
- $.fn.bootstrapValidator.DEFAULT_OPTIONS = $.extend({}, $.fn.bootstrapValidator.DEFAULT_OPTIONS, {
- events: {
- formInit: 'init.form.bv',
- formError: 'bv.form.error',
- formSuccess: 'bv.form.success',
- fieldAdded: 'added.field.bv',
- fieldRemoved: 'removed.field.bv',
- fieldInit: 'init.field.bv',
- fieldError: 'bv.field.error',
- fieldSuccess: 'bv.field.success',
- fieldStatus: 'status.field.bv',
- validatorError: 'bv.validator.error',
- validatorSuccess: 'success.validator.bv'
- }
- });
- $([
- '<form class="form-horizontal" id="eventForm2">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm2')
- .bootstrapValidator()
- .on('bv.form.success', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered bv.form.success event');
- })
- .on('success.form.bv', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered success.form.bv event');
- })
- .on('bv.form.error', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered bv.form.error event');
- })
- .on('error.form.bv', function(e) {
- $('#msg').html('form ' + $(e.target).attr('id') + ' triggered error.form.bv event');
- });
- this.bv = $('#eventForm2').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $.fn.bootstrapValidator.DEFAULT_OPTIONS = defaultOptions;
- $('#eventForm2').bootstrapValidator('destroy').remove();
- $.fn.bootstrapValidator.DEFAULT_OPTIONS = originalDefaultOptions;
- });
- it('triggers bv.form.success', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('form eventForm2 triggered bv.form.success event');
- });
- it('does not trigger success.form.bv', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).not.toEqual('form eventForm2 triggered success.form.bv event');
- });
- it('triggers bv.form.error', function() {
- spyOn(window, 'onerror');
- this.$email.val('this is"not\\allowed@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('form eventForm2 triggered bv.form.error event');
- expect(window.onerror).not.toHaveBeenCalled();
- });
- });
- describe('event field trigger with events changed', function() {
- var defaultOptions = $.fn.bootstrapValidator.DEFAULT_OPTIONS;
- beforeEach(function() {
- $.fn.bootstrapValidator.DEFAULT_OPTIONS = $.extend({}, $.fn.bootstrapValidator.DEFAULT_OPTIONS, {
- events: {
- formInit: 'init.form.bv',
- formError: 'bv.form.error',
- formSuccess: 'bv.form.success',
- fieldAdded: 'added.field.bv',
- fieldRemoved: 'removed.field.bv',
- fieldInit: 'init.field.bv',
- fieldError: 'bv.field.error',
- fieldSuccess: 'bv.field.success',
- fieldStatus: 'status.field.bv',
- validatorError: 'bv.validator.error',
- validatorSuccess: 'success.validator.bv'
- }
- });
- $([
- '<form class="form-horizontal" id="eventForm4">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm4')
- .bootstrapValidator()
- .on('success.field.bv', '[name="email"]', function(e, data) {
- $('#msg').html('triggered success.field.bv on ' + data.field);
- })
- .on('error.field.bv', '[name="email"]', function(e, data) {
- $('#msg').html('triggered error.field.bv on ' + data.field);
- })
- .on('bv.field.success', '[name="email"]', function(e, data) {
- $('#msg').html('triggered bv.field.success on ' + data.field);
- })
- .on('bv.field.error', '[name="email"]', function(e, data) {
- $('#msg').html('triggered bv.field.error on ' + data.field);
- });
- this.bv = $('#eventForm4').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $.fn.bootstrapValidator.DEFAULT_OPTIONS = defaultOptions;
- $('#eventForm4').bootstrapValidator('destroy').remove();
- $.fn.bootstrapValidator.DEFAULT_OPTIONS = originalDefaultOptions;
- });
- it('triggers success.field.bv', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).not.toEqual('triggered success.field.bv on email');
- });
- it('does not trigger bv.field.success', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('triggered bv.field.success on email');
- });
- it('does not trigger error.field.bv', function() {
- this.$email.val('Abc.example.com');
- this.bv.validate();
- expect($('#msg').html()).not.toEqual('triggered error.field.bv on email');
- });
- it('triggers bv.field.error', function() {
- spyOn(window, 'onerror');
- this.$email.val('Abc.example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('triggered bv.field.error on email');
- expect(window.onerror).not.toHaveBeenCalled();
- });
- });
- // ---
- // Validator events
- // ---
- function onEmailAddressValidatorSuccess(e, data) {
- $('#msg').html(data.validator + ' validator passed');
- };
- function onEmailAddressValidatorError(e, data) {
- $('#msg').html(data.validator + ' validator did not pass');
- };
- describe('event validator declarative', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress data-bv-emailaddress-onsuccess="onEmailAddressValidatorSuccess" data-bv-emailaddress-onerror="onEmailAddressValidatorError" />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm').bootstrapValidator();
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('trigger data-bv-emailaddress-onsuccess', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('emailAddress validator passed');
- });
- it('trigger data-bv-emailaddress-onerror', function() {
- this.$email.val('A@b@c@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('emailAddress validator did not pass');
- });
- });
- describe('event validator programmatically', function() {
- beforeEach(function() {
- $([
- '<form class="form-horizontal" id="eventForm">',
- '<div id="msg"></div>',
- '<div class="form-group">',
- '<input type="text" name="email" data-bv-emailaddress />',
- '</div>',
- '</form>'
- ].join('\n')).appendTo('body');
- $('#eventForm').bootstrapValidator({
- fields: {
- email: {
- validators: {
- emailAddress: {
- onSuccess: function(e, data) {
- $('#msg').html('emailAddress validator: onSuccess() called');
- },
- onError: function(e, data) {
- $('#msg').html('emailAddress validator: onError() called');
- },
- message: 'The email address is not valid'
- }
- }
- }
- }
- });
- this.bv = $('#eventForm').data('bootstrapValidator');
- this.$email = this.bv.getFieldElements('email');
- });
- afterEach(function() {
- $('#eventForm').bootstrapValidator('destroy').remove();
- });
- it('call onSuccess()', function() {
- this.$email.val('email@domain.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('emailAddress validator: onSuccess() called');
- });
- it('call onError()', function() {
- this.$email.val('A@b@c@example.com');
- this.bv.validate();
- expect($('#msg').html()).toEqual('emailAddress validator: onError() called');
- });
- });
|