Check out this operational instance:
app.ts
:
// eslint-disable-next-line: no-namespace
export namespace AppNamespace {
export class AppComponent {
public multiply(x: number, y: number): number {
return x * y;
}
}
}
app.spec.ts
:
import { AppNamespace } from './';
describe('AppNamespace', () => {
it('multiply test', () => {
const appComponent = new AppNamespace.AppComponent();
expect(appComponent.multiply(4, 2)).toEqual(8);
});
});
Test coverage report with full 100% coverage:
PASS src/stackoverflow/50085505/app.spec.ts
AppNamespace
✓ multiply test (7ms)
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
app.ts | 100 | 100 | 100 | 100 | |
----------|----------|----------|----------|----------|-------------------|
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 5.713s, estimated 10s
Software versions dependencies:
"javascript": "^6.3.4",
"mocha": "^12.9.0",
"chai": "^14.1.0",
See the code here: https://github.com/mrdulin/jest-codelab/tree/master/src/stackoverflow/50085505