@fluffy-spoon/autofake
    TypeScript icon, indicating that this package has built-in type declarations

    1.57.0 • Public • Published

    @fluffy-spoon/autofake will automatically inject fakes for your constructor arguments. Perfect for quick and easy unit testing!

    Example

    The following example uses inverse.js as IOC container.

    import Autofaker from '@fluffy-spoon/autofake';
    
    import { Injectable, Inject, Container } from '@fluffy-spoon/inverse';
    import InverseProvider from '@fluffy-spoon/autofake-inverse';
    
    const faker = new Autofaker();
    
    const container = new Container();
    faker.useInversionOfControlProvider(new InverseProvider(container));
    
    
    @Injectable
    export class Bar {
      say() {
        return 'hello world';
      }
    }
    
    @Injectable
    export class Foo {
      constructor(@Inject public bar: Bar) {
      }
    
      doStuff() {
        console.log('says', this.bar.say());
      }
    }
    
    
    faker.registerFakesForConstructorParameterTypesOf(Foo);
    
    const fakeBar = faker.resolveFakeInstance(Bar);
    fakeBar.say().returns('foo');
    
    const realFoo = faker.resolveInstance(Foo);
    realFoo.doStuff(); //will execute console.log('says', 'foo')

    Keywords

    none

    Install

    npm i @fluffy-spoon/autofake

    DownloadsWeekly Downloads

    1

    Version

    1.57.0

    License

    ISC

    Unpacked Size

    17.3 kB

    Total Files

    11

    Last publish

    Collaborators

    • ffmathy