1

I fear I do not fully understand JavaScrpt variable scoping. I have a function that looks like this:

return {
  response: '',

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

The idea is that birthMonthPrompt will ask a user for their birth month. After they enter it, I will have a value like 'November'. To test ths, I've written the following:

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);
    }
  );
});

When I execute this, I get an error that says:

ReferenceError: Can't find variable: response

I don't understand why my test can't find response. What am I doing wrong?

1
  • FYI, you also have to call the callback at some point (you don't seem to be doing anything with promptCallback). Commented Aug 18, 2014 at 15:27

1 Answer 1

1

You have a typo:

var reponse = 'November';

Should be:

var response = 'November';
Sign up to request clarification or add additional context in comments.

2 Comments

Don't forget to vote to close the question. We have a close reason for that.
doh! can't believe I didn't see that. Sometimes I miss my compiler :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.