diff --git a/test/index.html b/test/index.html index 1df110c2..ba4aa01b 100644 --- a/test/index.html +++ b/test/index.html @@ -58,6 +58,7 @@ + diff --git a/test/lib/helpers.js b/test/lib/helpers.js index 46744506..4fec5cec 100644 --- a/test/lib/helpers.js +++ b/test/lib/helpers.js @@ -26,4 +26,16 @@ chai.Assertion.addMethod('elements', function(expectedCollection) { expectedCollection.length, collection.length ); -}); \ No newline at end of file +}); + +function _inherits(subClass, superClass) { + subClass.prototype = Object.create(superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + }); + subClass.__proto__ = superClass; +} diff --git a/test/spec/baseClass.js b/test/spec/baseClass.js new file mode 100644 index 00000000..67beb705 --- /dev/null +++ b/test/spec/baseClass.js @@ -0,0 +1,42 @@ +describe('baseClass', function() { + + function MyComponent() { + Object.getPrototypeOf(MyComponent.prototype).constructor.apply(this, arguments); // super() + } + + _inherits(MyComponent, $.BaseClass); + + MyComponent.prototype.doSomething = function(value) { + return this.addClass(value); + }; + + it('should allow to extend from baseClass', function() { + var component = new MyComponent('body'); + expect(component instanceof MyComponent).to.be.true; + expect(component instanceof $.BaseClass).to.be.true; + expect(MyComponent.prototype instanceof $.BaseClass).to.be.true; + }); + + it('should extend properly from baseClass', function() { + var expected = getRndStr(), + component = new MyComponent('body'); + component.doSomething(expected); + expect(component.find).to.be.a('function'); + expect(document.body.className).to.contain(expected); + }); + + it('should accept Nodes, just like $()', function() { + var expected = $(document.body), + actual = new MyComponent(document.body); + expect(actual).to.have.same.elements(expected); + }); + + it('should be chainable', function() { + var className = getRndStr(), + expected = new MyComponent(document.body), + actual = expected.doSomething(className).addClass(className); + expect(actual).to.equal(expected); + expect(document.body.className).to.contain(className); + }); + +});