Aurelia element is just plain JS class, one thing you can do is to test it as a plain JS class without using StageComponent helper.
import {NavigationBarMenu} from '../src/navigation-bar-menu';
describe('NavigationBarMenu', function() {
it('...', function() {
const routerMock = {
currentInstuction: ...
navigate: (...) => {...} // write your assertions here.
};
// when use the class outside of aurelia context,
// all decorators `inject` `customElement` are ignored.
// you just feed the constructor with mocks.
const menu = new NavigationBarMenu(routerMock);
menu.newArchiveJob();
});
});
If you use StageComponent to test it in Aurelia context, there should be some API to modify DI container (to replace Router injection with a mock up version), but I don’t know the API. cc @bigopon
Very curious what @bigopon and others have to share. In the past when using StageComponent and needing to modify behavior of an injected dependency, or replace the injected dependency entirely, I’ve used two rather long winded approaches that I would love to see a more elegant solution shared for:
Make the main configure() function dynamic, so that it can be consumed by the stage component and when doing so alternate implementations are setup in Container (also, setRoot() is not called).
Leverage beforeBind() to replace or alter dependencies before the remainder of the lifecycle kicks off
Here is an example how i bootstrap differently for my tests:
And how it looks like in a test without StageComponent
You can do the same thing. The idea is to construct an Aurelia instance, give it the root container if desired, and bootstrap the test app with it, on a host you choose. So for what you want to do, you can do: