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

@mstream/di

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mstream/di - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

5

CHANGELOG.md

@@ -5,8 +5,9 @@ # Changelog

### 1.1.1 (2023-01-17)
## 1.1.0 (2023-01-17)
### Features
* improve error handling ([de68d45](https://github.com/mstream/di/commit/de68d45f0b7279b1bf0ce439acae1dea1e0ebdc3))
- improve error handling ([de68d45](https://github.com/mstream/di/commit/de68d45f0b7279b1bf0ce439acae1dea1e0ebdc3))

@@ -13,0 +14,0 @@ ### 1.0.6 (2023-01-17)

2

example/package.json

@@ -14,3 +14,3 @@ {

"test:js": "vitest run --dir test",
"test": "npm run test:js"
"test": "npm run test:js && npm start 2>/dev/null"
},

@@ -17,0 +17,0 @@ "author": "Maciej Laciak <maciej.laciak@gmail.com> (https://github.com/mstream/)",

{
"name": "@mstream/di",
"version": "1.1.0",
"version": "1.1.1",
"description": "",

@@ -5,0 +5,0 @@ "private": false,

@@ -6,23 +6,27 @@ import { describe, expect, it } from "vitest";

it(`allows to register and invoke creators`, () => {
const container = createContainer();
container.register(`string`, () => `abc`);
expect(container.context.string).toBe(`abc`);
const { string } = createContainer().register(
`string`,
() => `abc`
).context;
expect(string).toBe(`abc`);
});
it(`does not call a creator until requested`, () => {
const container = createContainer();
container.register(`error`, () => {
throw Error();
});
container.register(`string`, () => `abc`);
expect(container.context.string).toBe(`abc`);
const { string } = createContainer()
.register(`error`, () => {
throw Error();
})
.register(`string`, () => `abc`).context;
expect(string).toBe(`abc`);
});
it(`allow registring creators in any order`, () => {
const container = createContainer();
container.register(`string`, ({ number }) => `abc${number}`);
container.register(`number`, () => 1);
expect(container.context.string).toBe(`abc1`);
const { string } = createContainer()
.register(`string`, ({ number }) => `abc${number}`)
.register(`number`, () => 1).context;
expect(string).toBe(`abc1`);
});
it(`fails when creator is not a function`, () => {
const container = createContainer();
expect(() => container.register(`string`, `abc`)).toThrow(
expect(() => createContainer().register(`string`, `abc`)).toThrow(
/"string" creator is not a function/

@@ -32,4 +36,3 @@ );

it(`prevents from overriding creators`, () => {
const container = createContainer();
container.register(`string`, () => `abc`);
const container = createContainer().register(`string`, () => `abc`);
expect(() => container.register(`string`, () => `def`)).toThrow(

@@ -41,11 +44,10 @@ /"string" is already registered in the context/

let counter = 0;
const container = createContainer();
container.register(`string`, () => {
const { context } = createContainer().register(`string`, () => {
counter += 1;
return `abc`;
});
container.context.string;
expect(container.context.string).toBe(`abc`);
context.string;
expect(context.string).toBe(`abc`);
expect(counter).toBe(1);
});
});
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