-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure
Scope
is connected before accessing outlets (#648)
* Ensure `Scope` is connected before accessing outlets * Add tests for accessing outlets before they are initialized * Also test connect order
- Loading branch information
Showing
5 changed files
with
110 additions
and
26 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
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
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
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
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,45 @@ | ||
import { ControllerTestCase } from "../../cases/controller_test_case" | ||
import { OutletController } from "../../controllers/outlet_controller" | ||
|
||
const connectOrder: string[] = [] | ||
|
||
class OutletOrderController extends OutletController { | ||
connect() { | ||
connectOrder.push(`${this.identifier}-${this.element.id}-start`) | ||
super.connect() | ||
connectOrder.push(`${this.identifier}-${this.element.id}-end`) | ||
} | ||
} | ||
|
||
export default class OutletOrderTests extends ControllerTestCase(OutletOrderController) { | ||
fixtureHTML = ` | ||
<div data-controller="alpha" id="alpha1" data-alpha-beta-outlet=".beta">Search</div> | ||
<div data-controller="beta" id="beta-1" class="beta">Beta</div> | ||
<div data-controller="beta" id="beta-2" class="beta">Beta</div> | ||
<div data-controller="beta" id="beta-3" class="beta">Beta</div> | ||
` | ||
|
||
get identifiers() { | ||
return ["alpha", "beta"] | ||
} | ||
|
||
async "test can access outlets in connect() even if they are referenced before they are connected"() { | ||
this.assert.equal(this.controller.betaOutletsInConnectValue, 3) | ||
|
||
this.controller.betaOutlets.forEach((outlet) => { | ||
this.assert.equal(outlet.identifier, "beta") | ||
this.assert.equal(Array.from(outlet.element.classList.values()), "beta") | ||
}) | ||
|
||
this.assert.deepEqual(connectOrder, [ | ||
"alpha-alpha1-start", | ||
"beta-beta-1-start", | ||
"beta-beta-1-end", | ||
"beta-beta-2-start", | ||
"beta-beta-2-end", | ||
"beta-beta-3-start", | ||
"beta-beta-3-end", | ||
"alpha-alpha1-end", | ||
]) | ||
} | ||
} |