sinnbeck / laravel-dom-assertions Goto Github PK
View Code? Open in Web Editor NEWAdds DOM assertions to laravels test responses
License: MIT License
Adds DOM assertions to laravels test responses
License: MIT License
I think it would make sense to have a method opposite of the has
method on AssertElement
to check that certain attributes are not present on an element. Maybe something like this:
$this->get('/test')
->assertElementExists('a', function (AssertElement $a) {
$a->doesntHave('type', 'button');
$a->has('href', '/foo');
});
To be honest, this is more of a convenience thing for me, as for now I'm wrapping the element I'm testing in a <div>
and using doesntContain
to check for it that way but it just takes me longer to parse what my tests are doing when I come back to them at a later date :)
$this->get('/test')
->assertElementExists('div', function (AssertElement $div) {
$div->doesntContain('a', [
'type' => 'button',
]);
$div->contains('a', [
'href' => '/foo',
]);
});
When running composer require I get a compatibility error. Seems your version of symphony/css-selector is locked to 6.0 and laravel has v. 7.0
here's the error
- Root composer.json requires sinnbeck/laravel-dom-assertions ^1.3.1 -> satisfiable by sinnbeck/laravel-dom-assertions[v1.3.1].
- sinnbeck/laravel-dom-assertions v1.3.1 requires symfony/css-selector ^6.0 -> found symfony/css-selector[v6.0.0-BETA1, ..., 6.4.x-dev] but it conflicts with your root composer.json require (^7.0).
Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.```
I've noticed a problem when asserting the text of an element that contains duplicate spaces and vertical whitespace:
<div>
<p class="foobar">
Foo
<span>Bar</span>
</p>
</div>
$this->assertElementExists('p.foobar', fn ($el) => $el->has('text', 'Foo Bar'));
The assertion fails because the normalised text is:
Foo
Bar
I started adjusting Normalize::text()
to replace the offending characters, but it felt like the wrong approach.
I wondered if allowing the user to supply a function to use for comparison could be a potential solution?
Hello, I couldn't find a way to solve a problem. I am writing a test where I need to find all h2 tags and see if specific text does not appear in these tags.
Can't write simple assertDontSee because p paragraph can have same text as h2.
My html tree is similar to this:
<div>
<div>
<h2>my h2</h2>
<p>test</p>
</div>
<div>
<h2>my h2</h2>
<p>test</p>
</div>
</div>
This is my test where I am trying to solve this problem
$this->actingAs($user)
->get(route('my-route'))
->assertElementExists('h2', function (AssertElement $assertElement) {
$assertElement->doesntContainText('Specific text');
});
Is there a way to get array of elements and use doesntContainText on all items?
I'm not sure if I'm just missing something, but I can't seem to get the assertions to work when testing with Pest. Anytime I try calling a method, like assertElementExists
, I get this exception:
BadMethodCallException: Method Illuminate\Http\Response::assertElementExists does not exist.
I can fix that by Adding the DomAssertionsServiceProvider
to getPackageProviders()
in my base test case, however you have it marked as @internal
which makes me feel like this isn't the right thing to do:
protected function getPackageProviders()
{
return [
DomAssertionsServiceProvider::class,
];
}
Btw, I am using this in a package test suite with Orchestra, so it might be why I need to do that in my test case.
I think this package needs a AssertDatalist class, so that we can perform assertions on the datalist.
$form->assertDatalistExists('#authors', function(AssertDatalist $datalist) {
$datalist->hasValue('Jordan, Robert');
$datalist->hasValues([
'Eddings, David',
'Jordan, Robert',
]);
});
Tests fail with the following when using PHP8.3.8
BadMethodCallException: Call to undefined method Sinnbeck\DomAssertions\Asserts\AssertForm::getParser()
Adding
protected function getParser(): DomParser
{
return $this->parser;
}
to BaseAssert made it work, although what this indicates I don't know - perhaps that the magic __call method is being called rather than the methods in the traits?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.