jakerella / jquery-mockjax

The jQuery Mockjax Plugin provides a simple and extremely flexible interface for mocking or simulating ajax requests and responses
Other
2.11k stars 375 forks source link

cannot overwrite namespace with null #314

Closed tomeara closed 7 years ago

tomeara commented 7 years ago

In the documentation namespace: null should overwrite the global namespace... unless I'm missing something. Currently, it seems that the namespace is being retained for mocks; even if they are set to overwrite the namespace. Here's a test to illustrate what I mean:

t('should declare no namespace on individual mock', function(assert) {
    var done = assert.async();

    $.mockjaxSettings.namespace = '/api/v1';

    $.mockjax({
        url: 'one'
    });

    $.mockjax({
        url: '/two',
        namespace: null
    });

    $.ajax({
        url: '/api/v1/one',
        error: qunit.noErrorCallbackExpected,
        complete: function(xhr) {
            assert.equal(xhr.status, 200, 'Response was successful');
            $.ajax({
                url: '/two',
                complete: function(xhr) {
                    assert.equal(xhr.status, 200, 'Response was successful');
                    done();
                }
            });
        }
    });
});

Currently that test will fail unless I change the namespace for the second mock to be namespace: '/'. You can see here: https://github.com/jakerella/jquery-mockjax/blob/master/src/jquery.mockjax.js#L167 that we fallback to the mockjaxSettings.