Skip to content

Commit

Permalink
added: unit tests on conraner id
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Pasynok committed Nov 1, 2024
1 parent 63347a6 commit 895468a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createContainer } from '../index';

describe('feature.id not empty string', () => {
describe('container.id not empty string', () => {
test('happy', () => {
createContainer({
id: 'a',
Expand All @@ -10,7 +10,7 @@ describe('feature.id not empty string', () => {

test('unhappy', () => {
createContainer({
// @ts-expect-error feature id cannot be an empty string
// @ts-expect-error container.id cannot be an empty string
id: '',
onStart: () => ({ api: {} }),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createContainer, IDS_SET } from '../index';

const onStart = () => ({ api: {} });

describe('feature.id not empty string', () => {
describe('container.id not empty string', () => {
beforeEach(() => IDS_SET.clear());

test('happy', () => {
Expand All @@ -12,15 +12,15 @@ describe('feature.id not empty string', () => {
test('unhappy', () => {
expect(() =>
createContainer({
// @ts-expect-error feature id cannot be an empty string
// @ts-expect-error container.id cannot be an empty string
id: '',
onStart: () => ({ api: {} }),
}),
).toThrowError('Container ID cannot be an empty string.');
});
});

describe('feature.id is uniq', () => {
describe('container.id is uniq', () => {
beforeEach(() => IDS_SET.clear());

test('happy', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/createContainer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ExtractDeps<D extends Container<string, AnyObject>[]> = {
};

const ERROR = {
EMPTY_STRING_FEATURE_ID: 'Container ID cannot be an empty string.',
EMPTY_STRING_CONTAINER_ID: 'Container ID cannot be an empty string.',
CONTAINER_ID_NOT_UNIQ: 'Container ID must be unique.',
} as const;

Expand All @@ -32,7 +32,7 @@ type Params<
Deps extends NonEmptyTuple<AnyContainer> | void = void,
OptionalDeps extends NonEmptyTuple<AnyContainer> | void = void,
> = '' extends Id
? { id: never; error: typeof ERROR.EMPTY_STRING_FEATURE_ID }
? { id: never; error: typeof ERROR.EMPTY_STRING_CONTAINER_ID }
: Deps extends void
? OptionalDeps extends void
? {
Expand Down Expand Up @@ -81,7 +81,7 @@ const createContainer = <
params: Params<Id, API, Deps, OptionalDeps>,
): Container<Id, API> => {
if (params.id === '') {
throw new Error(ERROR.EMPTY_STRING_FEATURE_ID);
throw new Error(ERROR.EMPTY_STRING_CONTAINER_ID);
}

if (IDS_SET.has(params.id)) {
Expand Down

0 comments on commit 895468a

Please sign in to comment.