Skip to content

Commit

Permalink
feat: rewriting the matcher in typescript (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
erunion authored Nov 7, 2021
1 parent 41e7d9b commit 4adc9ab
Show file tree
Hide file tree
Showing 14 changed files with 556 additions and 129 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
@types/
coverage/
dist/
node_modules/
8 changes: 7 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{
"extends": "@readme/eslint-config",
"extends": [
"@readme/eslint-config",
"@readme/eslint-config/typescript"
],
"root": true,
"env": {
"jest": true
},
"rules": {
"@typescript-eslint/consistent-type-imports": "error"
}
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules/
@types/
coverage/
dist/
node_modules/
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ __tests__/
coverage/
.eslint*
.gitignore
jest.*
.prettier*
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
@types/
coverage/
dist/
node_modules/
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ A [Jest](https://jestjs.io/) custom matcher for asserting valid [HAR](https://en
## Installation

```sh
npm install --save-dev jest-expect-har
```

Once the package is installed you'll need to let Jest know about it by adding the following into your Jest config (either `jest.config.js` or under `jest` in `package.json`):

```json
"setupFilesAfterEnv": ["jest-expect-har"],
npm install jest-expect-har --save-dev
```

## Usage

```js
await expect(har).toBeAValidHAR();
import toBeAValidHAR from 'jest-expect-har';

expect.extend({ toBeAValidHAR });

test('should be a valid HAR', () => {
expect(har).toBeAValidHAR();
});

test('should not be a valid HAR', () => {
expect(invalidHar).not.toBeAValidHAR();
});
```
5 changes: 4 additions & 1 deletion __tests__/index.test.js → __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const har = require('./__fixtures__/har.valid.json');
import toBeAValidHAR from '../src';
import har from './__fixtures__/har.valid.json';

expect.extend({ toBeAValidHAR });

test('should accept a valid HAR', async () => {
await expect(har).toBeAValidHAR();
Expand Down
11 changes: 11 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
coveragePathIgnorePatterns: ['__tests__/__fixtures__/'],
globals: {
'ts-jest': {
tsconfig: 'tsconfig.test.json',
},
},
preset: 'ts-jest/presets/js-with-ts',
testPathIgnorePatterns: ['__tests__/__fixtures__/'],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(js?|ts?)$',
};
Loading

0 comments on commit 4adc9ab

Please sign in to comment.