vendredi 24 mars 2017

Laravel test sorting

I want to test whether my sorting works properly with Laravel TestCase. I have simple test page:

<div id="values">
    @foreach(['Value1', 'Value2'] as $value)
        <div class="test-class"></div>
    @endforeach
</div>

And now i want to test if the first .test-class element contains 'Value1'. I had tried different approaches, and had no success. Here are first one:

 public function testSorting()
{
    $this->visit(route('dummy'));
    $this->see('Value1');
    $this->seeInElement('.test-class:first-of-type', 'Value2');
}

This one resulted in exception:

Symfony\Component\CssSelector\Exception\ExpressionErrorException: "*:first-of-type" is not implemented.

Then I tried

$this->seeInElement('#values:first-child', 'Value2');

and my test when green. But it should be red, because first child is 'Value1'. It totally ignored ':first-child' part.

Then I tried

$this->seeInElement('#values:nth-child(1)', 'Value2');

and got green too. So this approach doesn't work either.

Have I missed something? Or there is no way to test order of elements on page with Laravel tests?

Aucun commentaire:

Enregistrer un commentaire