admin管理员组文章数量:1333172
Using TypeORM, I created some rather important queries with key functionality. Example: Only entities that match the anisationId may be returned.
// Typescript TypeORM code
const norm = await this.normRepository.findOne({
where: {
id: normId,
chapter: {
framework: {
anisationId: this.userServiceanisationId,
},
},
},
});
// Unit test
expect(normRepository.findOne).toHaveBeenCalledWith({
// The same query that I inserted in the code above
});
To me this test does not really test any query logic.
Coming from a .NET EF Core background it would look like this:
// C# EF Core code
var norm = await _dbContext.Norms.FirstAsync(n =>
n.Id == normId
&& n.Chapter.Framework.OrganisationId == _userServiceanisationId);
// Unit test
_dbContext.Setup(s => s.Norms).ReturnsDbSet( new List<Norm> {
// An example norm object, with connected chapter and framework
});
var result = await service.example();
Assert.NotNull(result) // Assert something that the method does.
In the EF Core unit test, some data is prepared on which the logic of the query actually runs.
Is there a way for TypeORM to test the query itself a bit better? What I foresee happening is that I update the query mistakenly, and then just copy paste the same query into the unit test.
本文标签: jestjsMeaningful unit tests for TypeORM queriesStack Overflow
版权声明:本文标题:jestjs - Meaningful unit tests for TypeORM queries - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742349368a2458174.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论