Search⌘ K
AI Features

Writing a Test Without Tools

Explore how to write basic automated tests for a pure email validation function without any testing tools. Learn to verify both valid and invalid cases manually and understand the challenges of scaling tests as complexity grows.

The function we want to test

Here is the function we want to test:

function isEmail(email) {
  const regex = new RegExp(/^[^@\s]+@[^@\s.]+\.[^@.\s]+$/);
  return regex.test(email);
}

The function validates whether an email address is formatted correctly. The function has no dependencies and doesn’t mutate the email parameter passed into it, which means it is a pure function. Pure functions are simple to test because all their logic is isolated.

We want to write the following two tests:

  • The function should return true when a valid email is passed into it.
  • The function should return false when an invalid email is passed into it.

Writing a happy path test

The first test we’ll write is to verify that the function correctly identifies a valid email address.

The test is available to execute further down the page. Before we run the ...