Writing test for your JS plugin

The cli tool tiddlywiki-plugin-dev and the SDK Modern.TiddlyDev now supports writing tests.

Read the tutorial site for details Modern.TiddlyDev: Document of Modern.TiddlyDev
, basically:

You can write tests in the wiki/tiddlers/tests folder, it will be a js file with meta file contains:


type: application/javascript

tags: $:/tags/test-spec

The $:/tags/test-spec tag will mark this tiddler as a test and will be executed when you run pnpm run test.

And test looks like this

describe('Filter tests', function() {
  // Test copy from https://github.com/Jermolene/TiddlyWiki5/blob/31ec1bdd50ce7fa58e4e2c8701106bd809c47dc3/editions/test/tiddlers/tests/test-filters.js
  it('should parse new-style rich operator suffixes', function() {
    expect($tw.wiki.parseFilter('[search:: four, , five,, six [operand]]')).toEqual(
      [{ prefix: '', operators: [{ operator: 'search', suffix: ': four, , five,, six ', suffixes: [[], ['four', 'five', 'six']], operands: [{ text: 'operand' }] }] }],
    );
  });
});
1 Like