mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-17 20:41:32 +00:00
a67466acc0
Replace easily identifiable object functions with method syntax: find \ -not \( \( -name node_modules -o -name .git -o -name vendor -o -name doc -o -name resources \) -prune \) \ -iname \*.js| xargs -rd\\n sed -ri 's%:\s*function\s*(\([^)]*\))%\1%g' Bug: T165036 Change-Id: I90693ee99a6a36dff820dd5ae6f6000429763058
51 lines
1 KiB
JavaScript
51 lines
1 KiB
JavaScript
import createContainer from '../../src/container';
|
|
|
|
QUnit.module( 'container', {
|
|
beforeEach() {
|
|
this.container = createContainer();
|
|
this.factory = this.sandbox.stub();
|
|
}
|
|
} );
|
|
|
|
QUnit.test( '#has', function ( assert ) {
|
|
this.container.set( 'foo', this.factory );
|
|
|
|
assert.ok( this.container.has( 'foo' ) );
|
|
} );
|
|
|
|
QUnit.test( '#get', function ( assert ) {
|
|
var service = {};
|
|
|
|
this.factory.returns( service );
|
|
|
|
this.container.set( 'foo', this.factory );
|
|
|
|
assert.strictEqual( service, this.container.get( 'foo' ) );
|
|
assert.strictEqual(
|
|
this.container,
|
|
this.factory.getCall( 0 ).args[ 0 ]
|
|
);
|
|
|
|
// ---
|
|
|
|
this.container.get( 'foo' );
|
|
|
|
assert.ok(
|
|
this.factory.calledOnce,
|
|
'It should memoize the result of the factory.'
|
|
);
|
|
|
|
// ---
|
|
|
|
assert.throws(
|
|
() => { this.container.get( 'bar' ); },
|
|
/The service "bar" hasn't been defined./
|
|
);
|
|
} );
|
|
|
|
QUnit.test( '#get should handle values, not just functions', function ( assert ) {
|
|
this.container.set( 'foo', 'bar' );
|
|
|
|
assert.strictEqual( 'bar', this.container.get( 'foo' ) );
|
|
} );
|