# jest-file-matcher

> A simple jest matcher extension to validate files

Latest version **1.0.2** (published 2022-07-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install jest-file-matcher
pnpm add jest-file-matcher
yarn add jest-file-matcher
bun add jest-file-matcher
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2022-07-02 |
| First published | 2021-04-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 27.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Filipe Pomar |
| Maintainers | filipomar |
| Keywords | jest, matcher, file, test, unit, web, dom |

## Links

- npm: https://www.npmjs.com/package/jest-file-matcher
- Repository: https://github.com/filipomar/jest-file-matcher
- Homepage: https://github.com/filipomar/jest-file-matcher#readme
- Issues: https://github.com/filipomar/jest-file-matcher/issues
- npm.io page: https://npm.io/package/jest-file-matcher

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2022-07-02
- 1.0.1 — 2021-04-30
- 1.0.0 — 2021-04-30

## README

# jest-file-matcher

A simple, Typescript ready, jest matcher extension to validate [files](https://developer.mozilla.org/en-US/docs/Web/API/File).

### Setup:

###### jest.config.ts / jest.config.js

Enable usage of the matcher in jest:

```ts
export default {
    /** Just add this project on your jest setup */
    setupFilesAfterEnv: ['jest-file-matcher'],
};
```

###### tsconfig.json

Import the matcher to typescript with:

```json
{
    "compilerOptions": {
        "typeRoots": ["./node_modules/jest-file-matcher"]
    }
}
```

### Usage:

###### Example.test.ts

```ts
describe('Example of test', () => {
    it('Test #1', async () => {
        await expect(new File([], 'example.tsx', { lastModified: 1 }))
            /** You can ignore some fields of the File as needed */
            .toBeFile(new File([], 'example.tsx', { lastModified: 0 }), { omit: ['lastModified'] });

        await expect(new File(['I am the content'], 'example.txt', { lastModified: 0 }))
            /** You can read the content of the file as you want */
            .toBeFile(new File(['I am the content'], 'example.txt', { lastModified: 0 }), { content: 'readAsDataURL' });

        await expect(new File(['I am the content'], 'example.txt', { lastModified: 0 }))
            /** Or ignore it all together*/
            .toBeFile(new File(['I am the content'], 'example.txt', { lastModified: 0 }), { content: false });

        await expect(new File(['I am the content'], 'example.txt', { lastModified: 0 }))
            /** And make sure that they don't match too*/
            .not.toBeFile(new File(["I'm not it however"], 'example.txt', { lastModified: 0 }));

        /**
         * See other cases on the typescript definition file!
         **/

        /**
         * Lastly, the code below will always fail with the warning:
         * The expected file is the same as the received, replace "toBeFile" with "toBe"
         */
        const file = new File(['I am the content'], 'example.txt', { lastModified: 0 });
        await expect(file).toBeFile(file);
    });
});
```

### LICENSE

MIT

---
_Source: https://npm.io/package/jest-file-matcher · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
