So, giving Claude Code browser access, for example, through the
Playwright plugin, can be pretty helpful.
But in general, giving AI tools a
way of verifying their work can be useful, and browser
access is not the only thing you can do there.
Instead, another powerful way of giving AI agents a
of verifying their work is by using good old testing,
unit testing, integration testing, end-to-end testing, all these kinds of
automated tests can be helpful. So here in this
project, I'll add Vitest
as a new testing library. It's a
very popular JavaScript testing library.
And now, of course, we could set up tests manually, but the
good thing about Claude Code and AI in general, of course, is
hand off tasks like that to AI. And we could send a prompt
like this to Claude Code informing us that we installed that testing
library and that we wanna do unit testing, in my case here, and that it
should set up the library appropriately and add unit
tests for all the key features, add mocks as needed and
split complex functions to simplify testing if needed.
I'll run this in plan mode because maybe it needs more information.
Now, indeed, it does have one follow-up question here,
and I want to work with a tests folder.
Got another question, extract those validation schemas
and submit the answers to let it continue planning,
and it seems like it wants to install a couple of dependencies,
then set up the configuration file for Vitest,
and then add a bunch of tests for sanitization, for
rendering of the rich text content,
for validation, plan some
refactoring to simplify testing and improve the code
there for overall, and also, as a mocking
strategy.
So that's looking good then I'll accept that.
Actually, I have one follow-up note which I sent to Claude Code.
As mentioned, you can always inject messages into an
existing task, and I accidentally canceled, which
another one. And I sent this one because Bun,
has its own built-in test runner, but I want to use that Vitest library
instead, and that's why I sent this extra message.
So it looks like it now did add its test, so let it
run it, and that's exactly the kind of feedback
talking about. It can now run its own
tests and fix any errors it detects.
So now it looks like all tests passed.
Now, one thing to watch out for is that AI can
be inclined to write tests that fit the code that's
already there. So you might wanna consider writing tests
first before you actually have the implementation, and
just as with the code that was generated by AI, you wanna review
those tests and see if the right things are tested,
AI to add more tests, and you can specifically specify which
tests it should add. But of course, combined with the browser access it
has, automated tests are a great way for creating such a
feedback loop where AI can validate its changes on its
own.