We asked an AI tool for a test file for the search box and the category buttons of a small shop. The reply had 11 tests. We ran them on the working shop, and all 11 passed on the first run.
Then we ran the same file on a copy of the shop with one bug added on purpose. We call that a planted bug. In that copy, the message "No products match your search." stays on screen after you clear the search. All 11 tests passed again.
So every test passed, and the file could not see that bug. This lecture is about how that happens.
Every AI-written test in this course is a real reply from an AI tool. The section "How these tests were collected", near the end of this lecture, says how we got them.
The examples in this course are Playwright tests, because that is what we asked for. Your exercises run in the framework you chose.
The check was true from the start
These lines come from the search test. We left out one check, which confirmed that the search found one product. searchInput is the search box. products is the list of product cards on the page.
await searchInput.fill('Alpine Tent');
await searchInput.clear();
await expect(products).toHaveCount(8);
await expect(page.getByTestId('no-results')).toBeHidden();
Line by line:
fill('Alpine Tent')types a search that finds one product.clear()empties the search box.toHaveCount(8)checks that all eight products are back.toBeHidden()checks that the "no results" message is not on screen.getByTestId('no-results')finds that message by its test id, a name that developers put on an element so that tests can find it.
The last line reads well. But "Alpine Tent" finds a product, so the message was never shown in this test. The check was true before the search, during it and after it. It could not fail in this test.
The bug only acts after a search that finds nothing. The test never made one and then cleared it. A check that something is gone means little unless you first saw it there.
A check that was true too early
The second example is harder to see. We gave the same tool a careful request about deleting a contact. It included the rule: Cancel keeps the contact. You will read that request in the last lecture.
The reply had two tests, and both passed on the working app. Then we ran them on a copy where Cancel deletes the contact anyway. Both passed again.
These lines show the Cancel click and the two checks that follow. We left out one comment. maya is the table row for the contact Maya Chen. before is the list of names read at the start.
await dialog.getByTestId('cancel-delete').click();
await expect(maya).toBeVisible();
await expect.poll(() => getContactNames(page)).toEqual(before);
Line by line:
- The first line clicks Cancel in the dialog.
- The second line checks that Maya Chen's row is on screen.
- The third line reads the names again and compares them with the list from the start.
This looks right. It checks the row, and it checks the whole list of names. Here is what the broken copy did, measured every quarter of a second after the click:
- At 0 ms and at 256 ms, Maya Chen's row was still in the table.
- At 511 ms, the row was gone and the page said "Contact deleted".
The page takes half a second to remove a contact. The test checked at once, saw the row, and finished.
The reason is in how these two checks work.
A retrying assertion is a check that Playwright tries again and again until it passes or the time runs out. toBeVisible is one.
It waits for something to become true, and it stops at the first success. It does not look again.
expect.poll works the same way. It calls the function again until the result matches. Here the result matched on the first read, so the check passed at once.
That is exactly what you want when you wait for a result to appear. It does not help when you need something to stay true.
The two tests differ in one way. The search test never made its bug act. This test did make the bug act, and then it checked before the damage showed.
Every "did not happen" check is true before the thing happens.
A second "did not happen" check does not help
We tried two repairs on the broken copy.
| Repair | Working app | Copy where Cancel deletes |
|---|---|---|
| Expect the "Contact deleted" message to be hidden, then check the row | passes | passes, so it misses the bug |
| Expect the dialog to be hidden, then check the row | passes | fails, so it catches the bug |
The first repair has the same problem as the test. The message is not on screen in the first half second, so "hidden" is true at once.
The second repair works for a different reason. The dialog closes only when the page has finished its work. On the working app that is at once. On the broken copy that is the moment the row is removed. So the test waits for something to become true, and only then looks at the row.
That gives a rule you can use: find the signal that ends the work, wait for it, then check the state.
Two limits come with it.
- Some pages show no such signal. Then the signal can be a response from the server, or a loading indicator leaving the page.
- The signal must be caused by the work. A dialog that closes on its own timer would be gone before the row was removed, and the check would pass on the bug. This dialog closes because the operation finished, which is why the repair works.
You can test a signal the same way we did. Run the test on a copy where the behaviour is broken. If it still passes, check whether the test triggered the bug, waited for the work and checked the affected result.
The same idea in plain JavaScript
Synchronous and asynchronous code shows a value that is read before the work has finished. There, the value was read too early and was wrong. Here, the value was read too early and was right, which is why the test passed.
The rule on another app
Parcel Desk is a fictional delivery app. It exists only in the code on this page. An address card has a Remove button, which opens a dialog with Keep address and Remove address. The code is for reading, not for running, because the app does not exist.
import { test, expect } from '@playwright/test';
test('Keep address leaves the address in the list', async ({ page }) => {
await page.goto('/addresses');
const home = page.getByTestId('address-card').filter({ hasText: '14 Mill Lane' });
await home.getByRole('button', { name: 'Remove' }).click();
const dialog = page.getByRole('dialog', { name: 'Remove this address' });
await dialog.getByRole('button', { name: 'Keep address' }).click();
await expect(dialog).toBeHidden();
await expect(home).toBeVisible();
});
filter({ hasText: '14 Mill Lane' }) picks the address card that contains that text.
The last two lines are the point. toBeHidden waits until the dialog has closed, which Parcel Desk does when its work is done. Only then does toBeVisible look at the card.
What a passing test tells you
A passing test tells you the app did what the test checked, at the moment it checked. It does not tell you the test checks the right thing, or checks it at the right time.
Reading the test is not enough to find out. Both tests above read well, and both would be easy to approve in a pull request. A pull request is a request to add a change to the team's code, which a teammate reviews first. What showed the gap was running each test against an app with a known bug. Verification on this site does that to your test.
A third test, for editing a contact, missed three bugs. It passed on the working app only after we corrected one button name, so it is not counted in this lecture. Lecture 4 covers it.
How these tests were collected
Every AI-written test in this course is real. We wrote each request, sent it once, and kept the first reply unchanged. Then we ran the test on the working app and on copies with a bug added on purpose.
There are fifteen test files.
- Twelve came from ChatGPT with its default model, on 3 December 2026. The model version was not recorded. ChatGPT was given only the request.
- Three came from Claude Code on the same day. It is a different tool, and it could read the app's source and run tests. We ran those three ourselves with the same tool we use to build this site, so they are not independent evidence.
We do not know whether every ChatGPT request started a new chat, or whether ChatGPT opened a page.
We used different tools and gave them different access. We cannot tell which difference affected the replies. All fifteen are Playwright tests, and we have none for other frameworks. Every example of AI-written code shown here comes from the twelve ChatGPT files.
What we looked for and did not find
We found no fixed waits and no failures hidden in try and catch in the twelve ChatGPT files. These runs could not tell us whether tests depended on their order.
The count is the twelve ChatGPT files described above. The three Claude Code files are left out of it, because that tool could read the app's source and we ran it ourselves.
- Fixed waits. A fixed wait pauses the test for a set time, such as two seconds. None of the twelve files has one. A test can still check at the wrong moment without one. The Cancel check above was true when it ran and false half a second later.
- Failures hidden in
tryandcatch. None of the twelve files has one. - Tests that only pass in a certain order. We could not measure this. The practice apps have no server, so no test could leave data behind for the next one, whatever the tool wrote. These files tell us nothing about this fault.
Twelve files from one tool on one day are a small sample. They do not show how AI tools write tests in general.
Your exercise. The shop's empty search message can stay on screen while a test passes. Write a test that fails when it does.
Remember this:
- A passing test proves the app did what the test checked, at the moment it checked.
- A check that something is gone means little unless you first saw it there.
- Every "did not happen" check is true before the thing happens.
- Find the signal that ends the work, wait for it, then check the state.
- Run the test on a broken copy of the app. A test that still passes is not checking that behaviour.
Reference: Assertions.