-
-
Notifications
You must be signed in to change notification settings - Fork 174
/
ApplicationFactory.spec.ts
48 lines (46 loc) · 1.38 KB
/
ApplicationFactory.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { describe, it, expect } from 'vitest';
import { ApplicationFactory, type ApplicationGetterType } from '@/application/ApplicationFactory';
import { ApplicationStub } from '@tests/unit/shared/Stubs/ApplicationStub';
describe('ApplicationFactory', () => {
describe('getApp', () => {
it('returns result from the getter', async () => {
// arrange
const expected = new ApplicationStub();
const getter: ApplicationGetterType = () => expected;
const sut = new SystemUnderTest(getter);
// act
const actual = await Promise.all([
sut.getApp(),
sut.getApp(),
sut.getApp(),
sut.getApp(),
]);
// assert
expect(actual.every((value) => value === expected));
});
it('only executes getter once', async () => {
// arrange
let totalExecution = 0;
const expected = new ApplicationStub();
const getter: ApplicationGetterType = () => {
totalExecution++;
return expected;
};
const sut = new SystemUnderTest(getter);
// act
await Promise.all([
sut.getApp(),
sut.getApp(),
sut.getApp(),
sut.getApp(),
]);
// assert
expect(totalExecution).to.equal(1);
});
});
});
class SystemUnderTest extends ApplicationFactory {
public constructor(costlyGetter: ApplicationGetterType) {
super(costlyGetter);
}
}