https://github.com/ts-graphviz/jest-graphviz
🃏 A plugin for jest that supports graphviz integration.
https://github.com/ts-graphviz/jest-graphviz
graphviz graphviz-dot jest jest-plugin testing testing-library typescript-library
Last synced: 6 months ago
JSON representation
🃏 A plugin for jest that supports graphviz integration.
- Host: GitHub
- URL: https://github.com/ts-graphviz/jest-graphviz
- Owner: ts-graphviz
- License: mit
- Created: 2019-11-10T08:47:53.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-01-18T02:37:57.000Z (over 2 years ago)
- Last Synced: 2024-10-29T20:21:26.691Z (over 1 year ago)
- Topics: graphviz, graphviz-dot, jest, jest-plugin, testing, testing-library, typescript-library
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/jest-graphviz
- Size: 544 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 27
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/kamiazya/jest-graphviz/actions?workflow=NodeCI) [](https://badge.fury.io/js/jest-graphviz) [](https://opensource.org/licenses/MIT) [](https://github.com/prettier/prettier) [](https://codeclimate.com/github/kamiazya/jest-graphviz/test_coverage)
# jest-graphviz
A plugin for [jest](https://jestjs.io/) that supports [graphviz](https://graphviz.gitlab.io/) integration.
## Installation
The plugin can then be installed using [npm](https://www.npmjs.com/):
[](https://nodei.co/npm/jest-graphviz/)
### yarn
```bash
yarn add -D jest-graphviz
```
### npm
```bash
npm install --save-dev jest-graphviz
```
## Configuration
Import `jest-graphviz` with the script specified in [`setupFilesAfterEnv`](https://jestjs.io/docs/en/configuration#setupfilesafterenv-array).
### Example
#### `jest.config.js`
```javascript
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
verbose: true,
collectCoverage: true,
setupFilesAfterEnv: [
// Add this.
'/config/jest/setup-jest.ts',
],
};
```
#### `config/jest/setup-jest.ts`
```typescript
import 'jest-graphviz';
```
## Requirement
This extension requires Graphviz.
If you don't have it installed, install it here[here](https://graphviz.gitlab.io/download/).
## Usage
### `toBeValidDot`
```typescript
describe('toBeValidDot test', () => {
it('matcher works', () => {
const dot = 'digraph g { a -> b; }';
expect(dot).toBeValidDot();
});
it('invalid dot', () => {
const dot = 'invalid';
expect(dot).not.toBeValidDot();
});
});
```
### `toBeValidDotAndMatchSnapshot`
```typescript
describe('toBeValidDotAndMatchSnapshot test', () => {
test('matcher works', () => {
const dot = 'digraph g { a -> b; }';
expect(dot).toBeValidDotAndMatchSnapshot();
});
});
```
### `toMatchDotJsonSnapshot`
```typescript
describe('toMatchDotJsonSnapshot test', () => {
test('matcher works', () => {
const dot = 'digraph g { a -> b; }';
expect(dot).toMatchDotJsonSnapshot();
});
});
```
> It depends on the JSON output format added in Graphviz 2.40.0.
## See Also
Graphviz-dot Test and Integration
- [ts-graphviz](https://github.com/ts-graphviz/ts-graphviz)
- Graphviz library for TypeScript.
- [@ts-graphviz/react](https://github.com/ts-graphviz/react)
- Graphviz-dot Renderer for React.
- [setup-graphviz](https://github.com/ts-graphviz/setup-graphviz)
- GitHub Action to set up Graphviz cross-platform(Linux, macOS, Windows).
## License
This software is released under the MIT License, see LICENSE.
## Author
[kamiazya(Yuki Yamazaki)](https://github.com/kamiazya)
[](https://ko-fi.com/W7W5VDNO)