在MVC中编写单元测试用例的正确方法遵循MVC架构

时间:2018-01-19 08:54:34

标签: javascript node.js unit-testing typescript

考虑以下示例:

a.js

import B from "b";
export default class A {
    classAMethod() {
       //do something
       let b = new B();
       b.classBMethod();
    }
}

b.js

import C from "c";
 export default class B {
    classBMethod() {
        return new Promise((resolve, reject) => {
        //do Something
        let c = new C();
        c.classCMethod().then((result) => {
           let computedResult = // do something with the result
           resolve(computedResult);
        }).catch((error) => {
            reject(error);
        })
      });
    }
 }

c.js

import * as redis from "redis";
import {Promise} from "bluebird";
let client = client.createClient();
Promise.promisifyAll(redis.RedisClient.prototype);

export default class C {
  classCMethod() {
     return client.getAsyc("someKey");
  }
}

现在我的问题是:

在我编写classAMethod()的单元测试用例时,我是否需要存根classBMethod()或者测试用例应该通过classBMethod()和存根redis' s createClient method,作为b模块导入c模块又需要创建redis客户端吗?

0 个答案:

没有答案