I'm finding it tough to test my client-side code without testing implementation details.

For example, lets say you are testing a login form that displays client-side validation errors and does not submit unless the email and password are present and correctly formatted.

You could write a test independent of classnames, etc. to check if the form did not submit (e.g. no POST request was sent) but if I want to check for specific errors I need to either a) rely on specific error messages or b) specific class names which are both liable to change.


1 Answer 1


Your goal should be to push as much logic as you can away from the UI surface into classes or methods that you can unit test independently of the UI surface.

function IsValidEmailAddress(string address)
    // return true if email address is valid

The classes or methods so created can be tested with go/no go conditions, so that you don't have to search for an error message. This is as true of client-side code as it is of server-side code.

  • 1
    Your question 1: sounds reasonable. May 29, 2018 at 15:29
  • 1
    Your question 2: presumably you are also validating server-side. May 29, 2018 at 15:29
  • 1
    You can test that once, by hand. May 29, 2018 at 15:35
  • 1
    If it's part of the UI surface, assume that you can't unit test it. That's why you push as much logic as you can away from the UI surface. May 29, 2018 at 15:38
  • 2
    I assume you have unit tests in the client. The UI logic doesn't have to be pushed into the server, just far enough away in the client so that you can unit test it. May 29, 2018 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.