Skip to content

Commit

Permalink
Improve error messages a bit, show hint when no registrations are found
Browse files Browse the repository at this point in the history
  • Loading branch information
Miki Leskinen committed Apr 23, 2012
1 parent e8a1281 commit d74c558
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/jasmine-fake-ajax.js
Expand Up @@ -19,12 +19,12 @@
} else if (!_.isEmpty(allFakeOptions)) {
var fakeOptions = findMatchingOptions(realOptions, allFakeOptions)
if (_.isEmpty(fakeOptions)) {
jasmine.FakeAjax.log.warn(messageWithContextInfo("No matching fake ajax options was found", realOptions))
jasmine.FakeAjax.log.warn(messageWithContextInfo("No matching fake ajax registration found.", realOptions))
} else {
callAvailableCallbackHandlers(realOptions, fakeOptions)
}
} else {
jasmine.FakeAjax.log.warn(messageWithContextInfo("There are no fake ajax options defined", realOptions))
jasmine.FakeAjax.log.warn(messageWithContextInfo("No fake ajax registrations found. Perhaps you forgot to register some using .fakeAjax?", realOptions))
}
}

Expand Down Expand Up @@ -231,7 +231,7 @@
}

function messageWithContextInfo(message, realOptions) {
return message + ", spec: '" + jasmine.getEnv().currentSpec.description + "', real ajax url: '" + realOptions.url + "'."
return message + " (spec: '" + jasmine.getEnv().currentSpec.description + "', actual ajax url that was called by application: '" + realOptions.url + "')"
}
})(jQuery, jasmine)

Expand Down
8 changes: 4 additions & 4 deletions spec/fake-ajax-spec.js
Expand Up @@ -566,17 +566,17 @@ describe('logging', function() {
describe('without fake ajax options', function() {
it('logs warning', function() {
$.get('/example')
expect(testLog.latestWarning()).toEqual("There are no fake ajax options defined, spec: " +
"'logs warning', real ajax url: '/example'.")
expect(testLog.latestWarning()).toEqual("No fake ajax registrations found. Perhaps you forgot to register some using .fakeAjax? (spec: " +
"'logs warning', actual ajax url that was called by application: '/example')")
})
})

describe('without matching url', function() {
it('logs warning with real url and spec description', function() {
fakeAjax({registrations:[{url: '/this'}]})
$.get('/that', function(){})
expect(testLog.latestWarning()).toEqual("No matching fake ajax options was found, spec: " +
"'logs warning with real url and spec description', real ajax url: '/that'.")
expect(testLog.latestWarning()).toEqual("No matching fake ajax registration found. (spec: " +
"'logs warning with real url and spec description', actual ajax url that was called by application: '/that')")
})
})

Expand Down

0 comments on commit d74c558

Please sign in to comment.