njct
TypeScript icon, indicating that this package has built-in type declarations

10.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(Car);
vehicle = inject(Car);
expect(vehicle).toBeA(Car);
expect(Car.count).toEqual(1);

Versions

Current Tags

Version History

Package Sidebar

Install

npm i njct

Weekly Downloads

84

Version

10.0.0

License

MIT

Unpacked Size

7.44 kB

Total Files

6

Last publish

Collaborators

  • iamthes