Skip to content

Commit

Permalink
Add tests for accessing outlets before they are initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoroth committed Jun 18, 2023
1 parent 387e197 commit 66484f3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/tests/controllers/outlet_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class OutletController extends BaseOutletController {
alphaOutletDisconnectedCallCount: Number,
betaOutletConnectedCallCount: Number,
betaOutletDisconnectedCallCount: Number,
betaOutletsInConnect: Number,
gammaOutletConnectedCallCount: Number,
gammaOutletDisconnectedCallCount: Number,
namespacedEpsilonOutletConnectedCallCount: Number,
Expand Down Expand Up @@ -46,11 +47,16 @@ export class OutletController extends BaseOutletController {
alphaOutletDisconnectedCallCountValue = 0
betaOutletConnectedCallCountValue = 0
betaOutletDisconnectedCallCountValue = 0
betaOutletsInConnectValue = 0
gammaOutletConnectedCallCountValue = 0
gammaOutletDisconnectedCallCountValue = 0
namespacedEpsilonOutletConnectedCallCountValue = 0
namespacedEpsilonOutletDisconnectedCallCountValue = 0

connect() {
this.betaOutletsInConnectValue = this.betaOutlets.length
}

alphaOutletConnected(_outlet: Controller, element: Element) {
if (this.hasConnectedClass) element.classList.add(this.connectedClass)
this.alphaOutletConnectedCallCountValue++
Expand Down
24 changes: 24 additions & 0 deletions src/tests/modules/core/outlet_order_tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ControllerTestCase } from "../../cases/controller_test_case"
import { OutletController } from "../../controllers/outlet_controller"

export default class OutletOrderTests extends ControllerTestCase(OutletController) {
fixtureHTML = `
<div data-controller="alpha" data-alpha-beta-outlet=".beta">Search</div>
<div data-controller="beta" class="beta">Beta</div>
<div data-controller="beta" class="beta">Beta</div>
<div data-controller="beta" 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 => {

Check failure on line 19 in src/tests/modules/core/outlet_order_tests.ts

View workflow job for this annotation

GitHub Actions / build

Replace `outlet` with `(outlet)`

Check failure on line 19 in src/tests/modules/core/outlet_order_tests.ts

View workflow job for this annotation

GitHub Actions / build

Replace `outlet` with `(outlet)`
this.assert.equal(outlet.identifier, "beta")
this.assert.equal(Array.from(outlet.element.classList.values()), "beta")
})
}
}

0 comments on commit 66484f3

Please sign in to comment.