我想在我的nodejs应用程序上进行一些单元测试,以测试用户在数据库中的插入或从数据库中读取用户。
我使用Objection.js这样的ORM,我通过网络搜索了如何进行这些测试,因此我发现Sinon来模拟数据库或模型。关于这个问题我也发现了这个问题{{ 3}}。
例如,如果我有一个表export class HomePage {
searchResults = [{
"details": [{
"user_id": "73",
"email": "ejazanwar777@gmail.com",
"token": "217808036f0215fee13aee8925574899"
}, {
"user_id": "94",
"email": "ejazanwar7dds77@gmail.com",
"token": "f4e9a701f9dae581ecbc2abf1470f88f"
}, {
"user_id": "98",
"email": "ejazanwar777dsggds@gmail.com",
"token": "3481a3c17a752ef136a4eadeaa0813f4"
}, {
"user_id": "99",
"email": "ejazanwar777@gmail.comsaasas",
"token": "6bd7941c8b501f798c8854047a395bdf"
}, {
"user_id": "100",
"email": "ejazanwar777jgfjgfjfg@gmail.com",
"token": "127934324e39ad681826322632f91259"
}, {
"user_id": "107",
"email": "ejazanwar77adsfdasf7@gmail.com",
"token": "1a6c860fc6d6a2875f4de371dee22b22"
}, {
"user_id": "108",
"email": "ejazanwar777@gmail.comdddd",
"token": "684aae9542ddc76f1f78c4360afe8846"
}, {
"user_id": "109",
"email": "jhddfhfdfdhdhfjhj@gmail.com",
"token": "069fe4f0ec2210c1e8eb9400486f1718"
}, {
"user_id": "110",
"email": "ejazanwar777@gmail.comssdssdd",
"token": "a10f3620d18466a0d5780749401052ad"
}]
}];
constructor(public navCtrl: NavController) {
}
}
包含10个用户,是否有任何解决方案可以获取此类表的所有行,例如,如果表中存在用户,则获取fetch?我不太了解嘲讽的概念,是否适合进行此类测试?
答案 0 :(得分:2)
有许多用于NodeJS单元测试的库,如Moca,Chai,Jasmine。
这里有一些教程链接:
https://www.codementor.io/davidtang/unit-testing-and-tdd-in-node-js-part-1-8t714s877
https://blog.risingstack.com/node-hero-node-js-unit-testing-tutorial/