-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@delayed causing unit test to fail #512
Comments
@rinobatin You can probably get this unit test working if you use I can only imagine this to be one of the following issues:
or
The above library works by running a mini Aurelia app lifecycle, so it imports your component dynamically, ensuring that the app is in the right state before you test your components. Here's an example of some tests I wrote for import {StageComponent} from 'aurelia-testing';
import {RouteLoader, AppRouter, Router} from 'aurelia-router';
import {TemplatingRouteLoader} from 'src/route-loader';
import {testConstants} from 'test/test-constants';
describe('router-view', () => {
let component;
beforeEach(done => {
done();
});
afterEach(done => {
component.viewModel.router.navigate('default').then(() => {
component.dispose();
done();
});
});
function bootstrap(component, defaultRoute, routeConfig) {
component.bootstrap(aurelia => {
aurelia.use.defaultBindingLanguage()
.defaultResources()
.history()
.developmentLogging();
aurelia.use.singleton(RouteLoader, TemplatingRouteLoader)
.singleton(Router, AppRouter)
.globalResources('src/router-view', 'src/route-href');
if (routeConfig) {
routeConfig.activationStrategy = 'replace';
routeConfig.route = 'route';
routeConfig = [defaultRoute, routeConfig];
} else {
routeConfig = [defaultRoute];
}
aurelia.use.container.viewModel = {
configureRouter: (config, router) => {
config.map(routeConfig);
}
};
});
function withDefaultViewport(routeConfig) {
let component = StageComponent
.withResources('src/router-view')
.inView('<router-view></router-view>');
bootstrap(component, { route: ['', 'default'], moduleId: 'test/module-default-slot', activationStrategy: 'replace'}, routeConfig);
return component;
}
it('has a router instance', done => {
component = withDefaultViewport({ moduleId: 'test/module-default-slot' });
component.create()
.then(() => {
expect(component.viewModel.router).not.toBe(undefined);
})
.then(done);
});
// ... etc As you can see, there are no imports for the (I've got a couple of helpers to set up routes etc but hopefully there's enough clarity in the above) |
@charlespockert, thanks for the reply. I also tried aurelia-testing but keep getting undefined StageComponent. I used jspm to install the npm package v0.3.0 but when I manually replaced the files with the github release, it worked!!! I logged an issue for someone to confirm. Are you using the aurelia-testing npm package? My setup is typscript/systemjs/jasmine/karma. |
Setting aside the issue with the aurelia-testing npm package, The view looks like this
|
I have a class that looks like this:
And unit test (spec)
If I run the test, I get
Error: Cannot read property 'get' of undefined. Error loading <spec>
. If I remove@delayed()
, it works. I looked the code ofdelayed
decorator and its usingContainer.instance.get()
(DI container). I thinkbeforeEach
has setup the container properly.A similar problem was logged here and it was suggested not to use DI inside decorators.
I like
@delayed
because it's more convenient thanAny suggestions to restructure my code so I can continue using
@delayed
?The text was updated successfully, but these errors were encountered: