1

I have done client side form validation using AngularJS, it works like a charm!

Then, I implemented server side validation and I want to test it by sending wrong data to the server. AngularJS (client side form validation) does not allow me to send wrong data to the server!

What can I do?

(Disabling Javascript cannot be a choice, because it will stop all ajax calls and thus no server side methods are called in my application)

Summery of the question:

users compromise front end validation (yes, it happens in practice!), how can I do the same for testing?

2
  • Can you explain how AngularJS does not allow you to send wrong data to server? You should be always able to do ajax call sending and properties from scope. Commented Oct 11, 2013 at 3:31
  • 2
    Model will not be populated with invalid data in AngularJS. Commented Oct 11, 2013 at 3:56

1 Answer 1

2

What you're asking doesn't make much sense. Angular does not prevent a request from being sent for any reason. If your form does that, it's only because you have coded it to do so. So, disabling validation in your case would be just a matter of commenting out the code that enforces it (that doesn't remain true if you're using custom validators. In that case, it may be a lot harder to disable validation altogether).

But, I wouldn't do that. In order to test your server-side validation, I suggest that you do one of the following:

  1. Write automated tests in the language your back-end was implemented and let them ensure your validation logic works (highly recommended);
  2. Manually do the tests by calling your back-end API directly. You could use Fiddler if you happen to be using Windows, or Postman for Google Chrome on any operating system.
Sign up to request clarification or add additional context in comments.

4 Comments

Validations on ng-model prevent data to be updated on model, so there is a problem. Still a good answer.
@Michael Benford The backend codes have been tested with appropriate tools, there is no problem. I just want to test how well my front end scripts are able to display the messages from the backend validation system, if the front end validation system is anyhow compromised (this happens in practice!) by the user. In other words, users compromise front end validation (it happens!), how can I do the same for testing?
@Chandermani You're right. I guess I'd mentioned it when I talked about custom validators ;)
@DUKE Oh, I see. In such a case, I'd say you should write automated tests for your client-side app so you can ensure it handles server-side errors correctly. Those tests could mock the server-side out and simulate bad responses. I guess you could also change your back-end code temporarily to do the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.