# fake-class

> fake-class instantiates objects with fake data.

Latest version **1.1.0** (published 2020-03-09) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install fake-class
pnpm add fake-class
yarn add fake-class
bun add fake-class
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2020-03-09 |
| First published | 2020-03-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | takkyuuplayer |
| Maintainers | takkyuuplayer |
| Keywords | fake, mock, test, testing |

## Links

- npm: https://www.npmjs.com/package/fake-class
- Repository: https://github.com/github.com/takkyuuplayer/ts-fake-class
- Homepage: https://github.com/takkyuuplayer/ts-fake-class#readme
- Issues: https://github.com/takkyuuplayer/ts-fake-class/issues
- npm.io page: https://npm.io/package/fake-class

## 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
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2020-03-09

## README

# fake-class

![CI](https://github.com/takkyuuplayer/ts-fake-class/workflows/CI/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/takkyuuplayer/ts-fake-class/badge.svg?branch=master)](https://coveralls.io/github/takkyuuplayer/ts-fake-class?branch=master)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)

fake-class instantiates objects with fake data.

## Requirement

* TypeScript version **3.3** or higher
* You have enabled the following settings in `tsconfig.json`:

   ```json
   "emitDecoratorMetadata": true,
   "experimentalDecorators": true,
   ```

## Install

1. Install the npm package:

    `npm install fake-class --save`

## Usage

### Basic Usage

```node
import { fakeClass, FakableClass, FakableField } from "fake-class";

@FakableClass()
class User {
  public id?: number;

  @FakableField(() => "takkyuuplayer@example.com")
  public email?: string;

  public active: boolean = true;
}

const user = fakeClass(User);
console.log(user); // User {active: true, email: 'takkyuuplayer@example.com' }
```

### Field Relation

You can set orders for fields to be resolved earlier than the others.
The default order is `Number.MAX_VALUE`.

Useful to relate faked fields.

```node
@FakableClass()
class User {
  @FakableField(() => 5, {
    order: 0
  })
  public id?: number;

  @FakableField((user: User) => `test-${user.id}@example.com`)
  public email?: string;
}

const user = fakeClass(User);
console.log(user); // User {id: 5, email: 'test-5@example.com' }
```

### More Examples

See more [examples](https://github.com/takkyuuplayer/ts-faker-decoration/tree/master/example).

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