Open lacolaco opened 1 week ago
Thanks for the input @lacolaco ! I agree that the current design works, but can be improved.
I was thinking of introducing a new createOutputListener
method as a work around.
test('output emits a value', async () => {
const submitFn = jest.fn();
const { outputs } = await render(SignalInputComponent, {
componentInputs: {
greeting: 'Hello',
name: 'world',
},
componentOutputs: {
submit: createOutputListener(submitFn)
}
});
await userEvent.click(screen.getByRole('button'));
expect(submitFn).toHaveBeenCalledWith('world');
});
That being said, I like your approach as well, and I think it will work better with Angular in the future (if something will be changed for Output
properties).
Let's think on this for a while - I'll also send a tweet of other opinions (feel free to do this as well).
Context
I think that there is some pains in spying on the output of a component, which is typified by the fact that you have to use type assertions by
any
. It is my opinion that the cost to pay for simply subscribing to events emitted by a component and inspecting their values can be lesser.https://github.com/testing-library/angular-testing-library/blob/main/apps/example-app/src/app/examples/22-signal-inputs.component.spec.ts#L51-L66
Goals
any
assertions in output testing scenarioIdea
This is a pseudo code and has not been strictly validated for feasibility.
outputs
to RenderResultoutputs.get(name)
can get a output ref by alias-aware nameoutputs.get(eventName)
The
eventName
should be same to its name in HTML template,<some-cmp (eventName)="..." />
. Angular'sComponentMirror
hasoutputs
getter which returns a record ofpropName
andtempalteName
of outputs. So I think ALT can map theeventName
to corresponding property.https://github.com/angular/angular/blob/main/packages/core/src/render3/component.ts#L104-L139