Ajax testing, mocking Jack

I use Jack as a fake JavaScript library. http://github.com/keronsen/jack . I also use qunit.

I have the following AJAX call in my javascript code that I am trying to write for a test.

$.ajax({
    url: $('#advance_search_form').attr('action'),
    type: 'post',
    dataType: 'json',
    data: parameterizedData,
    success: function(json) {
        APP.actOnResult.successCallback(json);
    }
});

The following code works.

jack(function() {
    jack.expect('$.ajax').exactly('1 time');
}

However, I want to check if all arguments are correctly presented. I tried to follow but did not work.

jack.expect('$.ajax').exactly('1 time').whereArgument(0).is(function(){

var args = arguments; ok (' http: // localhost: 3000 / users ', args.url, 'url must be valid'); // a similar test for many keys of an object});

I want to get arguments so that I can run a test battery.

+5
source share
1

:

.hasProperties():

jack.expect('$.ajax').once()
    .whereArgument(0).hasProperties({
         'type': 'post',
         'url': 'http://localhost:3000/users'
    });

... qunit:

var ajaxArgs;
jack.expect('$.ajax').once().mock(function() { ajaxArgs = arguments[0]; });
// ... the code that triggers .ajax()
equals('http://localhost:3000/users', ajaxArgs.url);

API- Jack ( ) , IMO.

.

+4

All Articles