Skip to content

Commit b54696c

Browse files
committed
Improved unit tests
1 parent c42fe0b commit b54696c

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

test/infrastructure/RepositoryFactory.spec.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ describe('RepositoryFactory', () => {
7272
repositoryFactory.getGenerationHash().subscribe(gh => {
7373
expect(counter).to.be.equals(1);
7474
expect(gh).to.be.equals('aaaa');
75-
done();
75+
repositoryFactory.getGenerationHash().subscribe(gh => {
76+
expect(counter).to.be.equals(1);
77+
expect(gh).to.be.equals('aaaa');
78+
done();
79+
})
7680
})
7781
})
7882

@@ -113,4 +117,39 @@ describe('RepositoryFactory', () => {
113117

114118
});
115119

120+
it('Should get NetworkType from memory', (done) => {
121+
122+
let counter = 0;
123+
124+
const repositoryMock: NetworkRepository = mock();
125+
126+
let expectedNetworkType = NetworkType.MIJIN_TEST;
127+
const observableOfBlockInfo = observableOf(expectedNetworkType).pipe(map(v => {
128+
counter++;
129+
return v;
130+
}));
131+
when(repositoryMock.getNetworkType()).thenReturn(observableOfBlockInfo);
132+
133+
expect(observableOfBlockInfo).to.be.equals(observableOfBlockInfo);
134+
135+
const repositoryFactory = new (class RepositoryFactoryHttpForTest extends RepositoryFactoryHttp {
136+
137+
createNetworkRepository(): NetworkRepository {
138+
return instance(repositoryMock);
139+
}
140+
})("http://localhost:3000", expectedNetworkType);
141+
142+
expect(counter).to.be.equals(0);
143+
repositoryFactory.getNetworkType().subscribe(networkType => {
144+
expect(counter).to.be.equals(0);
145+
expect(networkType).to.be.equals(expectedNetworkType);
146+
repositoryFactory.getNetworkType().subscribe(networkType => {
147+
expect(counter).to.be.equals(0);
148+
expect(networkType).to.be.equals(expectedNetworkType);
149+
done();
150+
})
151+
})
152+
153+
});
154+
116155
});

0 commit comments

Comments
 (0)