Skip to content

Commit

Permalink
Add tests for alias() and alias related utils
Browse files Browse the repository at this point in the history
  • Loading branch information
aedart committed Mar 25, 2024
1 parent 99e0119 commit 850cd36
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/browser/packages/support/container/container/alias.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Container } from "@aedart/container";

describe('@aedart/support/container', () => {
describe('alias', () => {

it('can register alias for binding', () => {
const container = new Container();

container
.bind('alpha', () => 'beta')
.alias('alpha', 'beta');

// -------------------------------------------------------------------- //

expect(container.isAlias('beta'))
.withContext('Alias not registered')
.toBeTrue();

expect(container.bound('beta'))
.withContext('Alias not bound')
.toBeTrue();

const result = container.make('beta');
expect(result)
.toBe('beta');
});

it('fails when identifier is the same as the alias', () => {
const container = new Container();

const callback = () => {
container.alias('a', 'a');
}

expect(callback)
.toThrowError(TypeError);
});

it('can obtain identifier for alias', () => {
const container = new Container();

container.alias('alpha', 'beta');

// -------------------------------------------------------------------- //

const result = container.getAlias('beta');
expect(result)
.toBe('alpha');
});
});
});

0 comments on commit 850cd36

Please sign in to comment.