# Testing plugins with mocha

**URL:** https://discourse.joplinapp.org/t/testing-plugins-with-mocha/27166
**Category:** Development
**Created:** [2 September 2022 09:59 UTC](https://discourse.joplinapp.org/t/testing-plugins-with-mocha/27166 "2022-09-02T09:59:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![banan314](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/banan314/32/5012_2.png) [@banan314](https://discourse.joplinapp.org/u/banan314)
#### Post date: [2 September 2022 09:59 UTC](https://discourse.joplinapp.org/t/testing-plugins-with-mocha/27166/1 "2022-09-02T09:59:50Z")

</div>

Has anybody tested the plugin using mocha or jest? I tried to run it, but I get errors all the time.

My code is  
**index.ts**

```auto
export function decreaseHeaderLevel(selection: string): string {
	return selection.replace(/^(#+)\s./, '#');
}

```

**index.spec.ts**

```auto
import { decreaseHeaderLevel } from 'src/index';

var assert = require('assert');
describe('Decrease level header', function () {
    describe('function', function () {
        it('should replace ## with #', function () {
            assert.equal(decreaseHeaderLevel('### rient'), '## rient');
        });
    });
});

```

**package.json**

```json
"test": "ts-mocha -p tsconfig.json src/**/*.spec.ts"

```

**tsconfig.json**

```json
{
	"typeRoots": [
		"types"
	],
	"compilerOptions": {
		"outDir": "./dist/",
		"module": "commonjs",
		"target": "es2015",
		"jsx": "react",
		"allowJs": true,
		"baseUrl": ".",
		"paths": {
			"@/*": [
				"src/*"
			]
		}
	},
	"include": [
		"src/**/*.ts",
		"tests/**/*.ts"
	],
	"exclude": [
		"node_modules",
		".vscode"
	]
}

```

And I get errors:

1. Running `mocha`

```auto
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /home/kamil/Documents/IT/projects/joplin-formatter-plugin/src/index.spec.ts

```

1. Running `ts-mocha`

```auto
> joplin-plugin-my-formatter@1.0.0 test
> ts-mocha -p tsconfig.json src/**/*.spec.ts

Error: Cannot find module 'src/index'
Require stack:
...
    at Object.<anonymous> (/home/kamil/Documents/IT/projects/joplin-formatter-plugin/src/index.spec.ts:1:1)

```

---

<div class="post-metadata">

### Author: ![JackGruber](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/jackgruber/32/3231_2.png) [@JackGruber](https://discourse.joplinapp.org/u/JackGruber)
#### Post date: [2 September 2022 10:46 UTC](https://discourse.joplinapp.org/t/testing-plugins-with-mocha/27166/2 "2022-09-02T10:46:24Z")

</div>

Yes with jest in my projects [joplin-plugin-backup](https://github.com/JackGruber/joplin-plugin-backup) and [joplin-plugin-note-overview](https://github.com/JackGruber/joplin-plugin-note-overview)
