-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5465c1
commit ec7de96
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
apps/server/src/modules/board/metrics/track-execution-time.decorator.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.` | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |