Compare commits

...

1 Commits

Author SHA1 Message Date
Sean Perkins
7d629ba9f1 test(angular): events are emitted once per emission 2022-11-04 11:45:28 -04:00
6 changed files with 86 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
describe('Angular Output Target', () => {
beforeEach(() => {
cy.visit('/output-target');
});
it('should emit one event per emission', () => {
/**
* Angular @Output() events aren't actual DOM events,
* instead they are an "EventEmitter" (RxJS Subject)
* that emits a change.
*
* In the Angular output target, we manually create
* a RxJS Subject (EventEmitter) for each DOM event,
* so that developers can use the same binding syntax
* and have the expected behavior that Angular events
* do not bubble up the DOM tree.
*
* We additionally "trick" Angular by creating
* @Output decorated properties for each DOM event
* on the component proxy class and manually clearing
* the decorated metadata. This allows Angular to
* not add its own event listener and cause duplicate
* event emissions for the web component events.
*/
cy.get('#ionChangeInput').type('a');
cy.get('#ionChangeEmittedCount').should('have.text', '1');
});
});

View File

@@ -73,6 +73,10 @@ const routes: Routes = [
}
]
},
{
path: 'output-target',
loadChildren: () => import('./output-target/output-target.module').then(m => m.OutputTargetModule)
}
];
@NgModule({

View File

@@ -0,0 +1,17 @@
import { NgModule } from "@angular/core";
import { RouterModule } from "@angular/router";
import { OutputTargetComponent } from "./output-target.component";
@NgModule({
imports: [
RouterModule.forChild([
{
path: "",
component: OutputTargetComponent
}
])
],
exports: [RouterModule]
})
export class OutputTargetRoutingModule { }

View File

@@ -0,0 +1,11 @@
<ion-content>
<p>This test template verifies key behaviors in the <code>@stencil/angular-output-target</code>.</p>
<ion-list>
<ion-item>
<ion-label>Events are emitted once</ion-label>
<ion-input id="ionChangeInput" type="text" (ionChange)="onIonChange()"></ion-input>
<p id="ionChangeEmittedCount">{{ ionChangeEmittedCount }}</p>
</ion-item>
</ion-list>
</ion-content>

View File

@@ -0,0 +1,15 @@
import { Component } from "@angular/core";
@Component({
selector: "app-output-target",
templateUrl: "./output-target.component.html",
})
export class OutputTargetComponent {
ionChangeEmittedCount = 0;
onIonChange() {
this.ionChangeEmittedCount++;
}
}

View File

@@ -0,0 +1,11 @@
import { NgModule } from "@angular/core";
import { IonicModule } from "@ionic/angular";
import { OutputTargetRoutingModule } from "./output-target-routing.module";
import { OutputTargetComponent } from "./output-target.component";
@NgModule({
imports: [IonicModule, OutputTargetRoutingModule],
declarations: [OutputTargetComponent]
})
export class OutputTargetModule { }