ak-mock-decorator
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

MockDecorator

Mock decorator to simulate API responses.

Getting started

Import MockDecoratorModule

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

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');
  }
}

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.02latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.02

Package Sidebar

Install

npm i ak-mock-decorator

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

61.2 kB

Total Files

27

Last publish

Collaborators

  • andykamga