mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 06:46:26 +00:00
ef0e4b4973
Also updated tests to use the new assert as an argument style Change-Id: I3c82b4b068134bba755ae4a5c26f5bb98d400c43
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
/**
|
|
* VisualEditor Factory tests.
|
|
*
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
module( 've.Factory' );
|
|
|
|
/* Stubs */
|
|
|
|
ve.FactoryObjectStub = function( a, b ) {
|
|
this.a = a;
|
|
this.b = b;
|
|
};
|
|
|
|
/* Tests */
|
|
|
|
test( 'register', 1, function( assert ) {
|
|
var factory = new ve.Factory();
|
|
assert.throws(
|
|
function() {
|
|
factory.register( 'factory-object-stub', 'not-a-function' );
|
|
},
|
|
/^Constructor must be a function, cannot be a string$/,
|
|
'throws an exception when trying to register a non-function value as a constructor'
|
|
);
|
|
} );
|
|
|
|
test( 'create', 2, function( assert ) {
|
|
var factory = new ve.Factory();
|
|
assert.throws(
|
|
function() {
|
|
factory.create( 'factory-object-stub', 23, { 'bar': 'baz' } );
|
|
},
|
|
/^Unknown object type: factory-object-stub$/,
|
|
'throws an exception when trying to create a object of an unregistered type'
|
|
);
|
|
factory.register( 'factory-object-stub', ve.FactoryObjectStub );
|
|
assert.deepEqual(
|
|
factory.create( 'factory-object-stub', 16, { 'baz': 'quux' } ),
|
|
new ve.FactoryObjectStub( 16, { 'baz': 'quux' } ),
|
|
'creates objects of a registered type and passes through arguments'
|
|
);
|
|
} );
|
|
|
|
test( 'lookup', 1, function( assert ) {
|
|
var factory = new ve.Factory();
|
|
factory.register( 'factory-object-stub', ve.FactoryObjectStub );
|
|
assert.strictEqual( factory.lookup( 'factory-object-stub' ), ve.FactoryObjectStub );
|
|
} );
|