{"record":{"id":"f6883c6d9bbed8ed","repo":"angular/angular.js","slug":"undefined-argument-the-argument-is-provided","errorCode":null,"errorMessage":"Undefined argument `{}`; the argument is provided but not defined","messagePattern":"Undefined argument `(.+?)`; the argument is provided but not defined","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/ngMock/angular-mocks.js","lineNumber":2097,"sourceCode":"\n        // Change url to `null` if `undefined` to stop it throwing an exception further down\n        if (angular.isUndefined(url)) url = null;\n\n        return $httpBackend[prefix](method, url, data, headers, keys);\n      };\n    });\n  }\n\n  function parseRouteUrl(url) {\n    var strippedUrl = stripQueryAndHash(url);\n    var parseOptions = {caseInsensitiveMatch: true, ignoreTrailingSlashes: true};\n    return routeToRegExp(strippedUrl, parseOptions);\n  }\n}\n\nfunction assertArgDefined(args, index, name) {\n  if (args.length > index && angular.isUndefined(args[index])) {\n    throw new Error('Undefined argument `' + name + '`; the argument is provided but not defined');\n  }\n}\n\nfunction stripQueryAndHash(url) {\n  return url.replace(/[?#].*$/, '');\n}\n\nfunction MockHttpExpectation(expectedMethod, expectedUrl, expectedData, expectedHeaders,\n                             expectedKeys) {\n\n  this.data = expectedData;\n  this.headers = expectedHeaders;\n\n  this.match = function(method, url, data, headers) {\n    if (expectedMethod !== method) return false;\n    if (!this.matchUrl(url)) return false;\n    if (angular.isDefined(data) && !this.matchData(data)) return false;\n    if (angular.isDefined(headers) && !this.matchHeaders(headers)) return false;","sourceCodeStart":2079,"sourceCodeEnd":2115,"githubUrl":"https://github.com/angular/angular.js/blob/d8f77817eb5c98dec5317bc3756d1ea1812bcfbe/src/ngMock/angular-mocks.js#L2079-L2115","documentation":"$httpBackend.when/expect (and every shortcut: whenGET, expectPOST, whenRoute, expectRoute, ...) validate the `url` slot with assertArgDefined: if an argument was provided at that position (args.length > index) but its value is undefined, they throw 'Undefined argument `url`; the argument is provided but not defined'. This distinguishes 'no URL given' (allowed, matches any URL) from 'URL given but undefined' (almost certainly a bug in the test data).","triggerScenarios":"$httpBackend.expectGET(undefined, headers); when(method, undefined); building the URL from a config object whose property is missing ($httpBackend.whenGET(CONFIG.apiBase)) where CONFIG.apiBase is undefined; a variable referenced with a typo so it evaluates to undefined at setup time.","commonSituations":"Expectation helpers driven by spec tables where one row lacks a URL; copy-pasting an expectation call and deleting the URL but leaving the trailing comma/args; environment-dependent base URLs that are undefined in the Karma test run; note only `url` is checked — data/headers may be passed undefined.","solutions":["Pass a concrete matcher for the url: a string, RegExp, or function(url) returning true.","If the URL is genuinely optional in your helper, branch instead of passing undefined: call when(method) with no second argument when you mean 'any URL'.","Fix the source of the undefined value — typo'd variable, missing config key, or setup code that has not initialized the URL yet."],"exampleFix":"// before\nvar base = config.apiBase; // undefined in tests\n$httpBackend.whenGET(base + '/users').respond([]); // throws: url provided but undefined\n\n// after\nvar base = config.apiBase || '';\n$httpBackend.whenGET(base + '/users').respond([]);","handlingStrategy":"validation","validationCode":"// Validate the url matcher before setting up the backend\nfunction validUrlMatcher(url) {\n  return typeof url === 'string' ||\n         url instanceof RegExp ||\n         typeof url === 'function';\n}\nif (!validUrlMatcher(url)) {\n  throw new Error('url matcher is undefined; check the config/spec data');\n}\n$httpBackend.whenGET(url);","typeGuard":"function isUrlMatcher(url) {\n  return url == null || // omitted = match any URL (valid)\n    typeof url === 'string' ||\n    url instanceof RegExp ||\n    typeof url === 'function';\n}","tryCatchPattern":null,"preventionTips":["Omit the url argument entirely rather than passing undefined when you mean 'any URL'.","Default optional base URLs in test config: var base = CONFIG.apiBase || '';","Only the url slot is validated — but apply the same discipline to data/headers to avoid silent mismatch."],"tags":["angular-mocks","http-backend","validation","undefined-argument"],"backgroundTag":"undefined-argument-validation","analyzedSha":"d8f77817eb5c98dec5317bc3756d1ea1812bcfbe","analyzedAt":"2026-08-21T20:36:31.651Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}