Вот решение для модульного теста:
xyz.ts
:
class xyz {
storingRepo: Object;
constructor() {
this.storingRepo = {};
}
storeProduct(a: string, b: string) {
const key = `${a}_${b}`;
this.storingRepo[key] = true;
}
}
export default new xyz();
xyz.test.ts
:
import xyz from './xyz';
describe('62045858', () => {
it('should pass', () => {
expect(Object.keys(xyz.storingRepo)).toHaveLength(0);
xyz.storeProduct('a', 'b');
expect(xyz.storingRepo).toHaveProperty('a_b');
expect(xyz.storingRepo['a_b']).toBeTruthy();
});
});
Результат теста с покрытием отчет:
PASS stackoverflow/62045858/xyz.test.ts (9.997s)
62045858
✓ should pass (3ms)
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
xyz.ts | 100 | 100 | 100 | 100 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 11.815s