# Turn a requirement into a test

## Read the rule

A support team needs request titles that tell staff what to look for. Accept a title only if it is text and has at least 10 characters after removing spaces at the beginning and end. Spaces inside the title still count.

Before writing code, decide what should happen at the boundary. `"Printer 01"` contains exactly 10 characters and should pass. `"  Slow PC  "` contains 11 characters as typed, but only seven after trimming, so it should fail. A missing value should also fail.

## Write down the expected result

A test needs two things: the input and the result the rule requires. If you simply record what the current code does, a defective function can pass its own tests. Write your expected outcomes from the rule first, then compare them with the code.

```js
function acceptsTitle(title) {
  return typeof title === 'string' && title.trim().length >= 10;
}
```

The type check runs first. If the input is not a string, JavaScript stops evaluating the right-hand side, so a missing value is rejected without trying to call `trim()`.

## Practise before reading the feedback

Change the threshold to eight. Decide whether `"  New card  "`, `"  Slow PC  "` and a missing value should pass, and write a short reason for each decision. Add a fourth example of your own that passes the old rule as well as the new one.

## Worked feedback

The title `"  New card  "` passes because it contains eight characters after trimming. `"  Slow PC  "` still fails because it contains seven. A missing value is not text and fails without raising an error. `"Printer 01"` passes both rules because it contains 10 characters. Keep all four tests: one proves the intended change and the others make sure the boundaries still behave as expected.
