Joshua's Cheatsheets - Js Testing
Light
help

Ava

Grouping Tests and Multiple Test Files

The recommended way (unless things change) to group tests (or emulate test suites) is by splitting up your tests by file.

There are two options for using multiple test files with Ava:

  • Option A: Make sure your files match the glob pattern matching of Ava

    • This is not exactly documented clearly, but Ava looks for certain patterns of files to automatically detect as tests. Glob patterns are here.
    • Directories:

      • /__tests__
      • /test
      • /tests
    • File patterns:

      • *.spec.{ext}
      • *.test.{ext}
      • *test-*.{ext}
      • test.{ext} (this is the default starter file)

Jest

Grouping Tests and Multiple Files

@TODO


Mocha

How to run a specific test

mocha --grep "{describeTextPattern}"

How to run a single test file / specific file

Just pass as last argument / input to mocha CLI. In the docs, they call this spec.

If you want to add a dedicated command to your package.json, so devs can run with a bunch of hard-coded flags before the filename, you might run into issues if you have hardcoded the glob pattern into mocha.opts or a different config file (see wont-fix GH issue).

If the above is true for you, I would recommend removing the hardcoded pattern from your options file and rewrite scripts to look something like this:

{
	"scripts": {
		"test": "mocha {globPattern}",
		"test-file": "mocha"
	}
}

Code coverage

Most popular is probably istanbul; it's built into Jest, and comes recommended with Ava.

Ignoring stuff

Markdown Source Last Updated:
Mon Oct 21 2019 05:21:54 GMT+0000 (Coordinated Universal Time)
Markdown Source Created:
Tue Sep 17 2019 10:21:29 GMT+0000 (Coordinated Universal Time)