Skip to content

Commit

Permalink
Updated unit test (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlhaufe authored Dec 10, 2020
1 parent 1ff059a commit 2ab7416
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/RescueDecorator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,57 @@
import Contracts from './';
import { MSG_DUPLICATE_RESCUE, MSG_INVARIANT_REQUIRED } from './Messages';

/**
* https://github.com/final-hill/decorator-contracts/issues/57
*/
describe('The @rescue decorator is non-static member decorator excluding properties', () => {
const {rescue} = new Contracts(true);

test('class decorator throws', () => {
expect(() => {
// @ts-ignore: Ignoring type error for JS test
@rescue(() => {})
class Base {}

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

test('static method decorator throws', () => {
expect(() => {
class Base {
@rescue(() => {})
static method(): void {}
}

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

test('instance method decorator does not throw', () => {
expect(() => {
class Base {
@rescue(() => {})
method(): void {}
}

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

test('instance property decorator throws', () => {
expect(() => {
class Base {
// @ts-ignore: Ignoring type error for JS test
@rescue(() => {})
foo = 3;
}

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

/**
* https://github.com/final-hill/decorator-contracts/issues/59
*/
Expand Down

0 comments on commit 2ab7416

Please sign in to comment.