Hi,
in V24.3 I’m try to verify that a click on a download link (Anchor) calls the download service. However, since the Anchor target is a resource, it doesn’t seem to work, it throws an exception when using anchorTester.click().
How do I test that the download service is called on anchor click?
private Anchor createDownloadAnchor() {
var anchor = new Anchor(
new StreamResource("myfiles.zip", this::onDownload), "");
anchor.getElement().setAttribute("download", true);
anchor.setId("download");
var button = new Button("Download My files");
button.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
anchor.add(button);
return anchor;
}
Junit / Mockito is not at fault here, but yes, that’s exactly what I’m trying to do - to verify that service is invoked. DownloadService is already mocked, it’s just that test(anchor).click(); results in IllegalStateException, it doesn’t get to calling downloadService.