attributefactory.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: document */
  6. 'use strict';
  7. var modules = bender.amd.require( 'document/attributefactory' );
  8. describe( 'create', function() {
  9. it( 'should create the same instance', function() {
  10. var AttributeFactory = modules[ 'document/attributefactory' ];
  11. var factory = new AttributeFactory();
  12. var attr1 = factory.create( 'foo', 'bar' );
  13. var attr2 = factory.create( 'foo', 'bar' );
  14. expect( attr1 ).to.equals( attr2 );
  15. expect( attr1 ).to.have.property( 'key' ).that.equals( 'foo' );
  16. expect( attr1 ).to.have.property( 'value' ).that.equals( 'bar' );
  17. } );
  18. it( 'should create the same instance even if object has different order', function() {
  19. var AttributeFactory = modules[ 'document/attributefactory' ];
  20. var factory = new AttributeFactory();
  21. var attr1 = factory.create( 'foo', { a: 1, b: 2 } );
  22. var attr2 = factory.create( 'foo', { b: 2, a: 1 } );
  23. expect( attr1 ).to.equals( attr2 );
  24. expect( attr1 ).to.have.property( 'key' ).that.equals( 'foo' );
  25. expect( attr1 ).to.have.property( 'value' ).that.deep.equals( { a: 1, b: 2 } );
  26. } );
  27. it( 'should create different objects', function() {
  28. var AttributeFactory = modules[ 'document/attributefactory' ];
  29. var factory = new AttributeFactory();
  30. var attr1 = factory.create( 'foo', 'bar' );
  31. var attr2 = factory.create( 'foo', 'baz' );
  32. expect( attr1 ).to.not.equals( attr2 );
  33. expect( attr1 ).to.have.property( 'key' ).that.equals( 'foo' );
  34. expect( attr1 ).to.have.property( 'value' ).that.equals( 'bar' );
  35. expect( attr1 ).to.have.property( 'key' ).that.equals( 'foo' );
  36. expect( attr2 ).to.have.property( 'value' ).that.equals( 'baz' );
  37. } );
  38. } );