https://github.com/ffmathy/fluffyspoon.javascript.testing.autofake
https://github.com/ffmathy/fluffyspoon.javascript.testing.autofake
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ffmathy/fluffyspoon.javascript.testing.autofake
- Owner: ffMathy
- Created: 2018-08-25T23:09:17.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-12-29T19:28:33.000Z (over 2 years ago)
- Last Synced: 2024-04-13T21:57:47.751Z (about 2 years ago)
- Language: TypeScript
- Size: 212 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
`@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.
```typescript
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')
```