Skip to content

Commit

Permalink
Testing with sub class (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBuchholz committed Feb 27, 2019
1 parent 2b044f1 commit ef7358c
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions test/attributes/decorator.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,52 @@ describe("attributes/decorator.es6", function () {

describe("Defining attributes on an ES6 class using decorators", function () {

beforeEach(function () {
var
Attribute,
Test,
SubclassOfTest;

before(function (done) {
gpf.require.configure({
clearCache: true
});
});

it("loads js file defining a class with attributes", function (done) {
gpf.require.define({
classes: "es6/class_with_attributes.js"
}, function (require) {

var
Attribute = require.classes.Attribute,
Test = require.classes.Test,
attributes = gpf.attributes.get(Test);

assert(Object.keys(attributes).length === 2);
assert(attributes.id.length === 1);
assert(attributes.id[0] instanceof Attribute);
assert(attributes.id[0].value === 1);
assert(attributes.reset.length === 1);
assert(attributes.reset[0] instanceof Attribute);
assert(attributes.reset[0].value === 2);

Attribute = require.classes.Attribute;
Test = require.classes.Test;
SubclassOfTest = require.classes.SubclassOfTest;
done();

}).then(undefined, done);
});

it("offers decorators to add attributes on class", function () {
var attributes = gpf.attributes.get(Test);
assert(Object.keys(attributes).length === 2);
assert(attributes.id.length === 1);
assert(attributes.id[0] instanceof Attribute);
assert(attributes.id[0].value === 1);
assert(attributes.reset.length === 1);
assert(attributes.reset[0] instanceof Attribute);
assert(attributes.reset[0].value === 2);
});

it("works on sub classes", function () {
var subclassAttributes = gpf.attributes.get(SubclassOfTest);
assert(Object.keys(subclassAttributes).length === 2);
assert(subclassAttributes.id.length === 1);
assert(subclassAttributes.reset.length === 2);
var sum = 0;
subclassAttributes.reset.forEach(function (attribute) {
assert(attribute instanceof Attribute);
assert(attribute.value === 2 || attribute.value === 3);
sum += attribute.value;
});
assert(sum === 5);
});

});

});

0 comments on commit ef7358c

Please sign in to comment.