1.0.0-beta.11 • Published 6 years ago

deceiver-core v1.0.0-beta.11

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

CircleCI

Deceiver

It's a simple library to create fake objects of exactly the same shape as passed class. It's designed to work with ES2015+ classes and their transpiled counterparts. It works well with TypeScript (since itself is written in TypeScript) and it's usability is proven in real-world projects.

Usage

import { Deceiver } from 'deceiver-core';

class Foo {
    get foo () {return 'foo'; }

    aMethod () {}
}

const fooDeceiver = Deceiver(Foo);

Object.prototype.hasOwnProperty.call(fooDeceiver, 'foo') //true
fooDeceiver.aMethod() //undefined

const fooDeceiverWithMixin = Deceiver(Foo, {
    foo: 'bar',
    aMethod () {
        return 'Hello!';
    },
});
fooDeceiverWithMixin.foo //'bar'
fooDeceiverWithMixin.aMethod //'Hello!'