【发布时间】:2013-03-02 06:55:00
【问题描述】:
我目前有两个函数,每个函数都有测试:
function A(x) {
// do A things
return Aresults;
}
function testA() {
// this put A through its test and make sure it does what it's supposed to
}
和
function B(x) {
// do B things which involve using A
return Bresults;
}
function testB() {
// this put B through its test and make sure it does what it's supposed to
}
我现在意识到 A 的唯一用途是在 B 中。所以我想重新分解以隔离和保护代码:
function B(x) {
function A(x) {
// do A things
return Aresults;
}
// do B things which involve using A
return Bresults;
}
function testB() {
// this put B through its test and make sure it does what it's supposed to
}
我的问题是,既然 A 是 B 的封闭函数,我该如何添加测试?即我的 testA 函数在哪里?
【问题讨论】:
标签: javascript unit-testing testing