mediawiki-extensions-Visual.../tests/ve2/ve.NodeFactory.test.js
Trevor Parscal 1798a478e7 Massive refactor of node trees, generalizing lots of previously dm only stuff
Change-Id: I9dbb7094f86338ea2e725ad29f66e9e4ca2b52ed
2012-05-09 21:11:09 -07:00

43 lines
1.1 KiB
JavaScript

module( 've.NodeFactory' );
/* Stubs */
ve.NodeFactoryNodeStub = function( a, b ) {
this.a = a;
this.b = b;
};
/* Tests */
test( 'register', 1, function() {
var factory = new ve.NodeFactory();
raises( function() {
factory.register( '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() {
var factory = new ve.NodeFactory();
raises( function() {
factory.create( 'stub', 23, { 'bar': 'baz' } );
},
/^Unknown node type: stub$/,
'throws an exception when trying to create a node of an unregistered type'
);
factory.register( 'stub', ve.NodeFactoryNodeStub );
deepEqual(
factory.create( 'stub', 16, { 'baz': 'quux' } ),
new ve.NodeFactoryNodeStub( 16, { 'baz': 'quux' } ),
'creates nodes of a registered type and passes through arguments'
);
} );
test( 'lookup', 1, function() {
var factory = new ve.NodeFactory();
factory.register( 'stub', ve.NodeFactoryNodeStub );
strictEqual( factory.lookup( 'stub' ), ve.NodeFactoryNodeStub );
} );