Skip to content

Commit

Permalink
test trackExecutionTimeDecorator
Browse files Browse the repository at this point in the history
  • Loading branch information
hoeppner-dataport committed Jun 13, 2024
1 parent b5465c1 commit ec7de96
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { TrackExecutionTime } from './track-execution-time.decorator';

class MockClassWithTrackingFunction {
trackExecutionTime(methodName: string, executionTime: number) {
console.log(`Executing method ${methodName} took ${executionTime}ms`);
}
}
class MockClassWithoutTrackingFunction {
hello() {
console.log('Hello');
}
}

describe('TrackExecutionTimeDecorator', () => {
describe('track', () => {
describe('when a tracking function is defined in the target object', () => {
it('should not throw an exception', () => {
const decorator = TrackExecutionTime();

const target = new MockClassWithTrackingFunction();
expect(() => decorator(target, 'nameOfFunctionBeingTracked', {})).not.toThrow();
});
});

describe('when no tracking function is defined in the target object', () => {
it('should throw an exception', () => {
const decorator = TrackExecutionTime();

const target = new MockClassWithoutTrackingFunction();
expect(() => decorator(target, 'nameOfFunctionBeingTracked', {})).toThrowError(
`The class MockClassWithoutTrackingFunction does not implement the required trackExecutionTime method.`
);
});
});
});
});

0 comments on commit ec7de96

Please sign in to comment.