2.0.1 • Published 6 years ago

ngx-mock v2.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

ngx-mock

A mocking utility library that builds on Angular In Memory Web Api library.

Usage

The library allows you to decorate methods in the InMemoryDbService implementation using the URL path so you can easily map mock endpoints to mock data.

import { matchRoute, MockPost } from 'ngx-mock';

export class InMemoryDb implements InMemoryDbService {
    createDb(reqInfo?: RequestInfo) {
        return [];
    }

    get(reqInfo: RequestInfo) {
        return matchRoute(this)('get', reqInfo);
    }

    put(reqInfo: RequestInfo) {
        return matchRoute(this)('put', reqInfo);
    }

    post(reqInfo: RequestInfo) {
        return matchRoute(this)('post', reqInfo);
    }

    delete(reqInfo: RequestInfo) {
        return matchRoute(this)('delete', reqInfo);
    }
    
    @MockPost('api/requests/approve')
    postRequestApprove(reqInfo) {
        const index = request.findIndex(r => r.requestId === reqInfo.req.body.requestId);
        const request = requests[index];
        request.state.approved = true;
        return { body: request };
    }
}
2.0.1

6 years ago

2.0.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago