Merge pull request #1033 from diox/resource-exists-no-regexp
refs #1032 - Don't use a regexp search for string search in resourceExists Please note that this breaks backward compatibility when passing a string to resourceExists(); previously the .search() String method was used, preventing passing url strings containing a question mark easily. We're now strictly checking for an exact match. For searching for a more flexible pattern, you can keep passing in a RegExp.
Showing
3 changed files
with
3 additions
and
3 deletions
... | @@ -1488,7 +1488,7 @@ Casper.prototype.resourceExists = function resourceExists(test) { | ... | @@ -1488,7 +1488,7 @@ Casper.prototype.resourceExists = function resourceExists(test) { |
1488 | switch (utils.betterTypeOf(test)) { | 1488 | switch (utils.betterTypeOf(test)) { |
1489 | case "string": | 1489 | case "string": |
1490 | testFn = function _testResourceExists_String(res) { | 1490 | testFn = function _testResourceExists_String(res) { |
1491 | return res.url.search(test) !== -1 && res.status !== 404; | 1491 | return res.url.indexOf(test) !== -1 && res.status !== 404; |
1492 | }; | 1492 | }; |
1493 | break; | 1493 | break; |
1494 | case "regexp": | 1494 | case "regexp": | ... | ... |
... | @@ -8,7 +8,7 @@ | ... | @@ -8,7 +8,7 @@ |
8 | <script id="loader"></script> | 8 | <script id="loader"></script> |
9 | <script> | 9 | <script> |
10 | setTimeout(function () { | 10 | setTimeout(function () { |
11 | document.querySelector("#loader").setAttribute("src", "dummy.js"); | 11 | document.querySelector("#loader").setAttribute("src", "dummy.js?querystring"); |
12 | }, 1000); | 12 | }, 1000); |
13 | </script> | 13 | </script> |
14 | </body> | 14 | </body> | ... | ... |
... | @@ -11,7 +11,7 @@ casper.test.begin("Basic resources tests", 5, function(test) { | ... | @@ -11,7 +11,7 @@ casper.test.begin("Basic resources tests", 5, function(test) { |
11 | test.assertResourceExists(function(res) { | 11 | test.assertResourceExists(function(res) { |
12 | return res.url.match("dummy.js"); | 12 | return res.url.match("dummy.js"); |
13 | }, "phantom image found via test Function"); | 13 | }, "phantom image found via test Function"); |
14 | test.assertResourceExists("dummy.js", "phantom image found via test String"); | 14 | test.assertResourceExists("dummy.js?querystring", "phantom image found via test String"); |
15 | }, function onTimeout() { | 15 | }, function onTimeout() { |
16 | test.fail("waitForResource timeout occured"); | 16 | test.fail("waitForResource timeout occured"); |
17 | }); | 17 | }); | ... | ... |
-
Please register or sign in to post a comment