Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nesting ajax calls inside mockjax, mockjax returning prematurely #134

Closed
tom-mayer opened this issue Mar 13, 2014 · 2 comments
Closed

Nesting ajax calls inside mockjax, mockjax returning prematurely #134

tom-mayer opened this issue Mar 13, 2014 · 2 comments

Comments

@tom-mayer
Copy link

Hi, I think I am running into a similar Issue here. I have a mocked call which in itself does a $.ajax to retrieve some data. In the .done() callback from the inner $.ajax I set this.responseText to the value returned by the call.

$.mockjax
       url: "something"
       response: (settings) ->
              $.ajax(
                  type: 'GET'
                  url: 'internet_somewhere'
                  dataType: 'json'              
              ).done((data) =>
                  #this is the right object here due to coffee script '=>'
                  this.responseText = data
              )

If I call this mock, it returns instantly with a value of undefined instead of waiting for responseText to be set. I also tried setting async:false on the mock / inner ajax / mock caller, all to no avail.

Am I doing something wrong or is this a real issue?

@jakerella
Copy link
Owner

Looks like #93 is trying to address this. We'll need to write a failing test to ensure this is tackled properly.

dcneiner added a commit that referenced this issue Aug 12, 2014
This solve the issues presented in both #93 and #134 without changing existing behavior.

The usage would include just adding a second paramater to your response function callback. When present, mockjax would wait for it to be called before finishing the request.

See the new test for an example.
@jakerella jakerella added this to the Mockjax 1.6.0 milestone Aug 14, 2014
@jakerella
Copy link
Owner

This should be resolved in master via PR #186.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants