Skip to content

Commit

Permalink
Merge pull request #625 from staudenmeir/page-assert
Browse files Browse the repository at this point in the history
[5.0] Fix with() and page assertions
  • Loading branch information
taylorotwell authored Mar 9, 2019
2 parents 6d6ab62 + 7170583 commit 7c19a13
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ public function visitRoute($route, $parameters = [])
* @return $this
*/
public function on($page)
{
$this->onWithoutAssert($page);

$page->assert($this);

return $this;
}

/**
* Set the current page object without executing the assertions.
*
* @param mixed $page
* @return $this
*/
public function onWithoutAssert($page)
{
$this->page = $page;

Expand All @@ -176,8 +191,6 @@ public function on($page)
$page::siteElements(), $page->elements()
));

$page->assert($this);

return $this;
}

Expand Down Expand Up @@ -330,7 +343,7 @@ public function with($selector, Closure $callback)
);

if ($this->page) {
$browser->on($this->page);
$browser->onWithoutAssert($this->page);
}

if ($selector instanceof Component) {
Expand Down
6 changes: 6 additions & 0 deletions tests/BrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ public function test_with_method_with_page()

$browser->visit($page = new BrowserTestPage);

$page->asserted = false;

$browser->with('prefix', function ($browser) use ($page) {
$this->assertInstanceof(Browser::class, $browser);
$this->assertEquals('body prefix', $browser->resolver->prefix);
$this->assertEquals($page, $browser->page);
$this->assertFalse($page->asserted);
});
}

Expand All @@ -109,10 +112,13 @@ public function test_within_method_with_page()

$browser->visit($page = new BrowserTestPage);

$page->asserted = false;

$browser->within('prefix', function ($browser) use ($page) {
$this->assertInstanceof(Browser::class, $browser);
$this->assertEquals('body prefix', $browser->resolver->prefix);
$this->assertEquals($page, $browser->page);
$this->assertFalse($page->asserted);
});
}

Expand Down

0 comments on commit 7c19a13

Please sign in to comment.