Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.0] Fix assertVueContains #638

Merged
merged 1 commit into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/Concerns/MakesAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,9 +737,10 @@ public function assertVueIsNot($key, $value, $componentSelector = null)
*/
public function assertVueContains($key, $value, $componentSelector = null)
{
PHPUnit::assertTrue(
Str::contains($this->vueAttribute($componentSelector, $key), $value)
);
$attribute = $this->vueAttribute($componentSelector, $key);

PHPUnit::assertIsArray($attribute, "The attribute for key [$key] is not an array.");
PHPUnit::assertContains($value, $attribute);

return $this;
}
Expand All @@ -755,9 +756,10 @@ public function assertVueContains($key, $value, $componentSelector = null)
*/
public function assertVueDoesNotContain($key, $value, $componentSelector = null)
{
PHPUnit::assertFalse(
Str::contains($this->vueAttribute($componentSelector, $key), $value)
);
$attribute = $this->vueAttribute($componentSelector, $key);

PHPUnit::assertIsArray($attribute, "The attribute for key [$key] is not an array.");
PHPUnit::assertNotContains($value, $attribute);

return $this;
}
Expand Down
44 changes: 44 additions & 0 deletions tests/MakesAssertionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,48 @@ public function test_assert_selected()
);
}
}

public function test_assert_vue_contains()
{
$driver = m::mock(stdClass::class);
$driver->shouldReceive('executeScript')->andReturn(['john']);

$resolver = m::mock(stdClass::class);
$resolver->shouldReceive('format')->with('@vue-component')->andReturn('body foo');

$browser = new Browser($driver, $resolver);

$browser->assertVueContains('users', 'john', '@vue-component');

try {
$browser->assertVueDoesNotContain('users', 'john', '@vue-component');
$this->fail();
} catch (ExpectationFailedException $e) {
$this->assertStringContainsString(
"Failed asserting that an array does not contain 'john'.",
$e->getMessage()
);
}
}

public function test_assert_vue_contains_with_no_result()
{
$driver = m::mock(stdClass::class);
$driver->shouldReceive('executeScript')->andReturn(null);

$resolver = m::mock(stdClass::class);
$resolver->shouldReceive('format')->with('@vue-component')->andReturn('body foo');

$browser = new Browser($driver, $resolver);

try {
$browser->assertVueContains('users', 'john', '@vue-component');
$this->fail();
} catch (ExpectationFailedException $e) {
$this->assertStringContainsString(
'The attribute for key [users] is not an array.',
$e->getMessage()
);
}
}
}