https://github.com/roziscoding/jest-ts-tocompile
https://github.com/roziscoding/jest-ts-tocompile
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/roziscoding/jest-ts-tocompile
- Owner: roziscoding
- Created: 2022-01-14T21:56:40.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-14T22:56:16.000Z (about 4 years ago)
- Last Synced: 2025-02-27T02:55:47.534Z (about 1 year ago)
- Language: TypeScript
- Size: 72.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
jes-ts-tocompile
---
Custom Jest matcher for testing if a typescript file compiles.
## Installation
1. Install with npm
```sh
npm i jest-ts-tocompile
```
2. Import and install `jest-ts-tocompile` in your jest [setup file](https://jestjs.io/docs/configuration#setupfilesafterenv-array).
```js
const toCompile = require('jest-ts-tocompile');
toCompile.install();
```
### With TypeScript
When using typescript, you need to add the jest type augmentations to your project. In order to do this, create a `jest.d.ts` file in your project root and add the following code:
```ts
declare namespace jest {
interface Matchers {
toCompile(): R;
}
}
```
## Usage
You can call `expect` passing the file path of the typescript file to test and then call `.toCompile()` to test if the file compiles.
```typescript
import path from 'path';
describe('example files are correct', () => {
it('should compile', () => {
expect(path.join(__dirname, './example.ts')).toCompile();
});
})
```