# mockument

> A utility for Jest to generate a mock document.body from an HTML file

Latest version **2.0.0** (published 2017-06-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install mockument
pnpm add mockument
yarn add mockument
bun add mockument
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2017-06-15 |
| First published | 2017-06-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Craig Morton |
| Maintainers | craigmorton |
| Keywords | jest, mock, html, document, file, testing |

## Links

- npm: https://www.npmjs.com/package/mockument
- Repository: https://github.com/CraigMorton/mockument
- Issues: https://github.com/CraigMorton/mockument/issues
- npm.io page: https://npm.io/package/mockument

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2017-06-15
- 1.0.1 — 2017-06-15
- 1.0.0 — 2017-06-14
- 0.0.2 — 2017-06-13
- 0.0.1 — 2017-06-13

## README

# mockument

A node utility for [Jest](https://github.com/facebook/jest) to create a mocked `document.body` from a local HTML file.

Jest provides a mocked `document` object in your tests, but `document.body` is empty. You could do `document.body.innerHTML = '<div id="app"/>'` in your `beforeEach` hook, but if you need much more HTML than that it can be annoying to write or read it as a JS string. `mockument` allows you to use an HTML file instead.

Pass the `mockument` function the **absolute** path to an HTML file from which you want to generate a `document.body` object. `mockument` will modify Jest's `document` object and set its `document.body` to the one generated from the `<body>` of the HTML file.

Usage example:
```js
import mockument from 'mockument'

describe('something', () => {

  beforeEach(() => {
    mockument(`${__dirname}/../../public/index.html`)
  })
})
```

Note: `mockument` uses and modifies Jest's `document` object, so it will only work if used somewhere where Jest provides it's mock `document` object in scope. It won't be able to find the `document` object if used in other nodejs contexts. (And it won't be able to find node's 'fs' module if used in the browser either!)

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