Advanced

Testing a content script as a fixture

A page on the internet is a page that changes. A fixture is a page that does not change, and a page that does not change is what makes a test a claim.

What you will see

finding change missing. Two counts is what makes it a finding.

About 1 min of reading

Try It

Count before and after

1

Write the fixture

printf '

a

\n
\n' > /tmp/f.txt; wc -l < /tmp/f.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
2. Two lines is a fixture, which is a file.
2

Count before

printf 'a\nb\n' | wc -l

Before you run it, say out loud what it will print. Then open the answer.

What it prints
2. The before is a count.
3

Count after and find

printf 'before 2 after 2\n' | awk '{print ($4==$2) ? "finding change missing" : "ok"}'

Before you run it, say out loud what it will print. Then open the answer.

What it prints
finding change missing. Two counts is what makes it a finding.

Data Flow

A fixture to a repeatable test
1 The fixture is written as a file
↓
2 The hard cases are put in the fixture
↓
3 The before and after are counted
↓
4 A difference is the finding
Why this works
Why the fixture is not the real page

The real page changes. A test against a page that changes is a test that fails for two reasons.

The failure at this step

A test that passes on the fixture and fails on the page. The missing hard case is the answer.

Examples

The fixture is written

A small page in a file. A file is what a test reads, and a test that reads a file is a test that is repeatable.

The test names the before and after

Two counts. Two counts is what makes a change that did not happen a finding.

The fixture has the hard case

A nested node and an empty node. Two hard cases is what makes a passing test a real pass.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← An off switch as a written state
Previous Lesson
An off switch as a written state
Next Lesson
Shipping with a review that names the reach
Shipping with a review that names the reach →