Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

njct

8.0.0 • Public • Published

inject

Inject a dependency (service locator pattern).

USAGE

// app.ts
import { inject } from 'njct';
const fs = inject('fs', () => require('fs'));
fs.readFileSync('data.json');
 
// app.spec.ts
import { injector } from 'njct';
injector.mock('fs', () => ({ readFileSync: () => 'result of call of fs.readFileSync()' }));
class Car {
    static count = 0;
    constructor() { Car.count++; }
}
let vehicle = inject.service(Car);
vehicle = inject.service(Car);
expect(vehicle).toBeA(Car);
expect(Car.count).toEqual(1);

Install

npm i njct

DownloadsWeekly Downloads

152

Version

8.0.0

License

MIT

Unpacked Size

37.4 kB

Total Files

18

Last publish

Collaborators

  • avatar