Skip to content
This repository has been archived by the owner on Feb 24, 2022. It is now read-only.

Commit

Permalink
Add tests for baseClass
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jul 22, 2015
1 parent 5f17d4a commit 2fb9e04
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/index.html
Expand Up @@ -58,6 +58,7 @@
</script>

<script src="spec/attr.js"></script>
<script src="spec/baseClass.js"></script>
<script src="spec/class.js"></script>
<script src="spec/contains.js"></script>
<script src="spec/css.js"></script>
Expand Down
14 changes: 13 additions & 1 deletion test/lib/helpers.js
Expand Up @@ -26,4 +26,16 @@ chai.Assertion.addMethod('elements', function(expectedCollection) {
expectedCollection.length,
collection.length
);
});
});

function _inherits(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
subClass.__proto__ = superClass;
}
42 changes: 42 additions & 0 deletions 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);
});

});

0 comments on commit 2fb9e04

Please sign in to comment.