TestCase Widget Used as Unit-Test - (Most Wanted 2025)

I was just reading https://tiddlywiki.com/#TestCaseWidget which says:

The $testcase widget is designed to present interactive example test cases

(bold emphasis mine).

And I thought that having something similar, but non-interactive would make a great tool for writing automated unit tests.

The simplest, rudimentary form could look like:

<$vars foo="1" bar="2" >
    <$assertequal name="Test that `foo` == `bar`" param1=<<foo>> param2=<<bar>> />
</$vars>

Which would display something like:

Test that `foo` == `bar` : OK

or

Test that `foo` == `bar` : FAIL

foo = 1

bar = 2

After the recent Working with lists in TiddlyWiki discussion, ideally such an assert widget should support at least lists as well, to spare the user from doing explicit manual voodoo with enlist and just somehow be able to pass filters into the widget as well.

And Help with summing two variables(Solved) shows that it would be nice if such an assert widget could also wikify content passed to it.

Having such a widget would amplify the temptation to do Test Driven Development when writing wikitext logic or complex filters, when refactoring existing filters into functions etc

Perhaps this can be done with a custom widget, like this:

\widget $assert.equal(name,param1,param2)
<<name>>
<%if [<param1>match<param2>] %>
OK
<%else%>
FAIL
<!-- Display variables -->
<%endif%>
\end

The testcase widget is used for unit tests. As soon as there is an ExpectedResult tiddler, it acts like a test.

See: ControlPanels → Info → Advanced → Test Cases

If they fail they look like Failed Testcases

We also use the MultiTiddlerFiles to run some TW automatic tests. See the test-edition in the GitHub repo. All of them are testcase tiddlers.

Does a bunch of .tid files mean those tests can be run in a fully automated way only in a NodeJS TiddlyWiki setup?

The tests linked in the GitHub repo are run by our Node.js based automated tests. We use the jasmine test framework.

Whenever a PR is created, Netlify runs the automated tests.

But as you can see using the TW links, when the test are shown, they are also evaluated using the browser. So we can have both if needed.