Skip to content

Commit

Permalink
more test cases and remove useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
y1j2x34 committed Nov 13, 2017
1 parent c9a4986 commit 3b37d86
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
12 changes: 1 addition & 11 deletions Class.js
Expand Up @@ -31,11 +31,6 @@
return !fn(input);
};
},
or: function(fn, fm) {
return function(input) {
return fn(input) || fm(input);
};
},
and: function(fn, fm) {
return function(input) {
return fn(input) && fm(input);
Expand Down Expand Up @@ -516,12 +511,7 @@
});
}

function copyDescriptors(origin, dest, propNames, accept) {
if (isFunction(accept)) {
propNames = propNames.filter(function(name) {
return accept(origin, dest, name);
});
}
function copyDescriptors(origin, dest, propNames) {
propNames.forEach(function(name) {
copyDescriptor(origin, dest, name);
});
Expand Down
24 changes: 24 additions & 0 deletions test/decorate.js
Expand Up @@ -40,6 +40,9 @@ describe('test decorate', () => {
expect(() => {
Airplane.decorate(function(){});
}).toThrow();
expect(() => {
Class.decorate();
}).toThrow();
});
it('decorate contrustor: decorator should be called', () => {
var decorators = {
Expand Down Expand Up @@ -191,4 +194,25 @@ describe('test decorate', () => {
}).not.toThrow();
expect(thrownSpy).toHaveBeenCalled();
});
it('decorate object: should not throw', () => {
var airplane = new Airplane();
expect(() => {
Class.decorate(airplane, {});
}).not.toThrow();
});
it('decorate object: "*" decorates all methods', () => {
var airplane = new Airplane();
var decorator = {
before: function(){}
};
var beforeSpy = spyOn(decorator, 'before');

Class.decorate(airplane, {
'*': decorator
});

airplane.fly();

expect(beforeSpy).toHaveBeenCalled();
});
});

0 comments on commit 3b37d86

Please sign in to comment.