Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fluffy-spoon/autofake

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fluffy-spoon/autofake

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

  • 1.57.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

@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')

FAQs

Package last updated on 10 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc