Skip to main content

Test accepted and rejected cases

Test accepted and rejected order IDs. Then change the pattern to see a test fail.

Define the intended format​

This guide uses ORD- followed by four ASCII digits. Select JavaScript, remove all flags, and use:

^ORD-[0-9]{4}$

Add positive and negative cases​

  1. Open Unit Tests.
  2. Select Add unit test for each row.
  3. Set Assertion target to regex.
  4. Select the expected result in Assertion.
InputCriterionPurpose
ORD-0042does matchOrdinary accepted value
ORD-9999does matchFour digits
ORD-42does not matchToo few digits
ORD-00000does not matchToo many digits
XORD-0001does not matchExtra prefix
Empty inputdoes not matchMissing value
  1. Open Unit test actions (⋮) and select Run tests.
  2. Verify that all expectations pass.

If the list hides some results, select Show all tests in Unit test actions.

Inspect a failing test​

  1. Change {4} to {2,4}.
  2. Run the same tests.
  3. Inspect the failure for ORD-42.
  4. Restore {4}.
  5. Run the tests again.

The negative case fails because the changed pattern accepts two-digit IDs. Restoring {4} restores the required format.

Include a line-ending boundary​

Without m, the JavaScript pattern rejects ORD-0042\n. Enabling m permits a match on the first line. Here, \n represents an actual newline, rather than two typed characters.

Keep m disabled for this identifier field. A full-match comparison can also guard against a later flag change. The classification guide shows this comparison in JavaScript.

Choose tests or multiple strings​

Unit tests record expected outcomes and report whether each case passes. Multiple test strings let you explore results across separate editable inputs. A saved workspace preserves the unit tests for later changes.