# ak-mock-decorator

> Mock decorator to simulate API responses.

Latest version **1.0.0** (published 2021-05-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install ak-mock-decorator
pnpm add ak-mock-decorator
yarn add ak-mock-decorator
bun add ak-mock-decorator
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-05-21 |
| First published | 2021-05-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 59.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Andy Kamga |
| Maintainers | andykamga |
| Keywords | angular, mock-decorator, end to end, decorator, mock, e2e, ak |

## Links

- npm: https://www.npmjs.com/package/ak-mock-decorator
- npm.io page: https://npm.io/package/ak-mock-decorator

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.0.0

## Alternatives

- [pagerjs](https://npm.io/package/pagerjs.md) — 60 weekly downloads
- [whistle.savefor-mock](https://npm.io/package/whistle.savefor-mock.md) — 4 weekly downloads
- [facebook-ads-library-api](https://npm.io/package/facebook-ads-library-api.md) — 0 weekly downloads
- [@comp-markdown/wireframe](https://npm.io/package/@comp-markdown/wireframe.md) — 0 weekly downloads
- [generador-datos-mx](https://npm.io/package/generador-datos-mx.md) — 0 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2021-05-21

## README

# MockDecorator

Mock decorator to simulate API responses.

## Getting started

Import `MockDecoratorModule`

```javascript
import { MockDecoratorModule } from 'ak-mock-decorator';

imports: [
	MockDecoratorModule.forRoot()
]

// Or with config

imports: [
    MockDecoratorModule.forRoot({
    	disable: false,
    	endpoint: "http://my-fake-endpoint"
    })
]
```



Add `MockMapping` method decorator

```javascript
import { HttpClient } from '@angular/common/http';
import { MockMapping } from 'ak-mock-decorator';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';

export const PRODUCTS_MOCK = [
  { id: 1, title: 'Product 1' },
  { id: 2, title: 'Product 2' },
  { id: 3, title: 'Product 3' },
  { id: 4, title: 'Product 4' },
];

@Injectable({
  providedIn: 'root',
})
export class ApiService {
  constructor(private http: HttpClient) {}

  @MockMapping([{ disable: false, delay: 600, body: PRODUCTS_MOCK }])
  getProduct(): Observable<any> {
    return this.http.get('http://api-endpoint/products');
  }

  @MockMapping([
    { body: { name: 'User 0' } },
    { uri: '/users/1', body: { name: 'User 1' } },
    { uri: '/users/2', body: { name: 'User 2' } },
  ])
  getUser(): Observable<any> {
    return this.http.get('http://api-endpoint/users/1');
  }
}

```

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