Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix invoking actions for events dispatched during connect
Fixes #222 Co-Authored-By: Sam Stephenson <sstephenson@gmail.com>
- Loading branch information
1 parent
364ca73
commit 6129975
Showing
3 changed files
with
36 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/@stimulus/core/src/tests/cases/action_timing_tests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Controller } from "../.." | ||
import { ControllerTestCase } from "../controller_test_case" | ||
|
||
class ActionTimingController extends Controller { | ||
static targets = [ "button" ] | ||
buttonTarget!: HTMLButtonElement | ||
event?: Event | ||
|
||
connect() { | ||
this.buttonTarget.click() | ||
} | ||
|
||
record(event: Event) { | ||
this.event = event | ||
} | ||
} | ||
|
||
export default class ActionTimingTests extends ControllerTestCase<ActionTimingController> { | ||
controllerConstructor = ActionTimingController | ||
identifier = "c" | ||
fixtureHTML = ` | ||
<div data-controller="c"> | ||
<button data-target="c.button" data-action="c#record">Log</button> | ||
</div> | ||
` | ||
|
||
async "test triggering an action on connect"() { | ||
const { event } = this.controller | ||
this.assert.ok(event) | ||
this.assert.equal(event && event.type, "click") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters