Skip to content

Commit

Permalink
[v3] Fix Reactive Attribute Browser test (#5879)
Browse files Browse the repository at this point in the history
* fix reactive browser test - cannot mutate reactive prop

* fix reactive browser test - can_pass_a_reactive_property_from_parent_to_child

* fix order tests
  • Loading branch information
luanfreitasdev committed Jul 22, 2023
1 parent a46bd3f commit b358009
Showing 1 changed file with 67 additions and 2 deletions.
69 changes: 67 additions & 2 deletions src/Features/SupportReactiveProps/BrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,70 @@ public function can_pass_a_reactive_property_from_parent_to_child()

public function inc() { $this->count++; }

public function dec() { $this->count--; }

public function render() { return <<<'HTML'
<div>
<h1>Parent count: <span dusk="parent.count">{{ $count }}</span>
<button wire:click="dec" dusk="parent.dec">dec</button>
<button wire:click="inc" dusk="parent.inc">inc</button>
<livewire:child :$count />
</div>
HTML;
}
},
'child' => new class extends Component {
#[Reactive]
public $count;

public function render() { return <<<'HTML'
<div>
<h1>Child count: <span dusk="child.count">{{ $count }}</span>
</div>
HTML;
}
}
])
->assertSeeIn('@parent.count', 0)
->assertSeeIn('@child.count', 0)

->waitForLivewire()->click('@parent.inc')
->assertSeeIn('@parent.count', 1)
->assertSeeIn('@child.count', 1)

->waitForLivewire()->click('@parent.inc')
->assertSeeIn('@parent.count', 2)
->assertSeeIn('@child.count', 2)

->waitForLivewire()->click('@parent.dec')
->assertSeeIn('@parent.count', 1)
->assertSeeIn('@child.count', 1)

->waitForLivewire()->click('@parent.dec')
->assertSeeIn('@parent.count', 0)
->assertSeeIn('@child.count', 0)

->waitForLivewire()->click('@parent.dec')
->assertSeeIn('@parent.count', -1)
->assertSeeIn('@child.count', -1)

->waitForLivewire()->click('@parent.inc')
->assertSeeIn('@parent.count', 0)
->assertSeeIn('@child.count', 0);
}

/** @test */
public function can_throw_exception_cannot_mutate_reactive_prop()
{
Livewire::visit([
new class extends Component {
public $count = 0;

public function inc() { $this->count++; }

public function render() { return <<<'HTML'
<div>
<h1>Parent count: <span dusk="parent.count">{{ $count }}</span>
Expand Down Expand Up @@ -48,9 +112,10 @@ public function render() { return <<<'HTML'
->assertSeeIn('@parent.count', 1)
->assertSeeIn('@child.count', 1)
->waitForLivewire()->click('@child.inc')
->waitFor('#livewire-error')
->click('#livewire-error')
->assertSeeIn('@parent.count', 1)
->assertSeeIn('@child.count', 1)
;
->assertSeeIn('@child.count', 1);
}

/** @test */
Expand Down

0 comments on commit b358009

Please sign in to comment.