Closed FabienTaillon closed 7 years ago
There are a couple of approaches that you could take,
Expand component's interface via aura:method or event handlers to make it easier for the tests to invoke logic. Third party access can still be controlled via access checks. This pattern is similar to declaring methods as package-private while unit testing java.
Extract reusable code out of components into javascript libs/modules. Utility methods (e.g. a sorting algorithm) can then be tested in isolation and pulled in as needed by lightning components. This blog post talks about this in more detail.
Restrictions around what can be accessed/invoked are controlled by the platform (access checks, locker-service etc.) and apply to component tests as well. Based on personal experience, I think this does makes sense from test-quality perspective as it avoids issues going uncaught due to difference in behavior based on context/mode.
Ok, thanks !
Is there a way to test a method that is not exposed through the component's public interface ? We may have some methods that need to be tested, but that we don't want to expose.
In exempleTests it seems that all methods are called via an
aura:method
in the related component.