Skip to content

Commit

Permalink
Fixes link assertion with single or double quote (#965)
Browse files Browse the repository at this point in the history
* Fixes link assertion with single or double quote

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* Update InteractsWithElements.php

* Update MakesAssertions.php

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
crynobone and taylorotwell authored Feb 12, 2022
1 parent 4c2f1d2 commit bc9fd27
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/Concerns/InteractsWithElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ public function clickLink($link, $element = 'a')
{
$this->ensurejQueryIsAvailable();

$selector = addslashes(trim($this->resolver->format("{$element}:contains({$link}):visible")));
$selector = addslashes(trim($this->resolver->format("{$element}")));

$this->driver->executeScript("jQuery.find(\"{$selector}\")[0].click();");
$link = str_replace("'", "\\\\'", $link);

$this->driver->executeScript("jQuery.find(`{$selector}:contains('{$link}'):visible`)[0].click();");

return $this;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Concerns/MakesAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,12 @@ public function seeLink($link)
{
$this->ensurejQueryIsAvailable();

$selector = addslashes(trim($this->resolver->format("a:contains('{$link}')")));
$selector = addslashes(trim($this->resolver->format('a')));

$link = str_replace("'", "\\\\'", $link);

$script = <<<JS
var link = jQuery.find("{$selector}");
var link = jQuery.find(`{$selector}:contains('{$link}')`);
return link.length > 0 && jQuery(link).is(':visible');
JS;

Expand Down
4 changes: 2 additions & 2 deletions tests/WaitsForElementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,13 @@ public function test_wait_for_link()
{
$driver = m::mock(stdClass::class);
$driver->shouldReceive('executeScript')
->times(2)
->times(3)
->andReturnTrue();

$link = 'https://laravel.com/docs/8.x/dusk';

$script = <<<JS
var link = jQuery.find("body a:contains(\'{$link}\')");
var link = jQuery.find(`body a:contains('{$link}')`);
return link.length > 0 && jQuery(link).is(':visible');
JS;

Expand Down

0 comments on commit bc9fd27

Please sign in to comment.