Skip to content

Commit

Permalink
Implemented Unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mlhaufe committed Sep 26, 2019
1 parent 47acd66 commit 4e67868
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/InvariantDecorator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,4 +663,51 @@ describe('An invariant decorator must accept multiple assertions', () => {
return Stack;
}).not.toThrow();
});
});

/**
* Requirement 187
* https://dev.azure.com/thenewobjective/decorator-contracts/_workitems/edit/187
*/
describe('A subclass with its own invariants must enforce all ancestor invariants', () => {
test('Debug Mode', () => {
let {invariant} = new Contracts(true);

expect(() => {
@invariant(
self => self instanceof Base,
self => self != null
)
class Base {}

@invariant(self => self instanceof Sub)
class Sub extends Base {}

return new Sub();
}).not.toThrow();

expect(() => {
@invariant(self => self instanceof Array)
class Base {}

@invariant(self => self instanceof Sub)
class Sub extends Base {}

return new Sub();
}).toThrow(AssertionError);

expect(() => {
@invariant(
self => self instanceof Base,
'I thought I was a Base!'
)
class Base {}

@invariant(self => self instanceof Array)
// @ts-ignore : Ignore unused error
class Sub extends Base {}

return new Base();
}).not.toThrow();
});
});

0 comments on commit 4e67868

Please sign in to comment.