Testng JavaScript回调

时间:2014-08-18 15:20:34

标签: javascript

我担心我不完全了解JavaScrpt变量范围。我有一个看起来像这样的函数:

return {
  response: '',

  birthMonthPrompt: function(question, promptCallback) {
    this.dialogText = question;
  }
};

想法是birthMonthPrompt会询问用户他们的出生月份。进入后,我会得到像'十一月'那样的价值。为了测试,我写了以下内容:

it('should prompt the user', function() {
  var reponse = 'November';
  myService.response= response;

  myService.birthMonthPrompt('Please choose your birth month:', 
    function(userResponse) {
    expect(userResponse).toBe(this.response);
    }
  );
});

当我执行此操作时,我收到一条错误消息:

ReferenceError: Can't find variable: response

我不明白为什么我的测试无法找到答案。我做错了什么?

1 个答案:

答案 0 :(得分:1)

你有一个错字:

var reponse = 'November';

应该是:

var response = 'November';