Comments (8)
@butterfieldcons you should try it like this @Inject(Router) router: Router
. Inject
is exported by angular2/angular2
from angular-seed.
Still getting an error. Also tried with the forwardRef syntax. I have no doubt it would work outside karma/jasmin with angular bootstrap, but got to have a tests!!!!! Everything else works except the Router. Thanks.
Chrome 45.0.2454 (Windows 7 0.0.0): Executed 1 of 4 SUCCESS (0 secs / 0.003 secs
Chrome 45.0.2454 (Windows 7 0.0.0) About component should work FAILED
Error: Timeout - Async callback was not invoked within timeout specified
by jasmine.DEFAULT_TIMEOUT_INTERVAL.
import {Component, View, NgFor, Inject} from 'angular2/angular2';
import {Router} from 'angular2/router';
import {NamesList} from '../../services/NameList';
import { forwardRef, Binding } from 'angular2/di';
@Component({
selector: 'about'
})
@View({
templateUrl: './components/about/about.html?v=<%= VERSION %>',
directives: [NgFor]
})
export class About {
router: Router;
constructor(public list: NamesList, @Inject(Router) router: Router) {
this.router = router;
}
addName(newname) {
this.list.add(newname.value);
newname.value = '';
}
}
from angular-seed.
Will have a look at it, but something like this (router test) binded to the rootTestComponent might solve the problem.
from angular-seed.
Ok thanks, traced bindings.js - the pic below shows it failing. This scenario occurs when I did this in the spec. using the @Inject(Router) in the about.ts just fails outright with no error (which would work in a type angular2 bootstrap(ed) application.
@Component({selector: 'test-cmp', bindings: [NamesList, Router]})
from angular-seed.
Guessing something like this is what is needed. I'll give it a try early tonight since I'm going somewhere for the day. Seems simple enough, just need to figure out how to work with 'bootstrap' along with the 'TestComponentBuilder'. This code is from route_config_spec.ts under the test/router folder.
import {
AsyncTestCompleter,
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xdescribe,
xit,
} from 'angular2/test_lib';
import {bootstrap} from 'angular2/bootstrap';
import {Component, Directive, View} from 'angular2/metadata';
import {DOM} from 'angular2/src/dom/dom_adapter';
import {bind} from 'angular2/di';
import {DOCUMENT} from 'angular2/src/render/render';
import {Type} from 'angular2/src/facade/lang';
import {
ROUTER_BINDINGS,
Router,
RouteConfig,
APP_BASE_HREF,
ROUTER_DIRECTIVES
} from 'angular2/router';
import {ExceptionHandler} from 'angular2/src/core/exception_handler';
import {LocationStrategy} from 'angular2/src/router/location_strategy';
import {MockLocationStrategy} from 'angular2/src/mock/mock_location_strategy';
class _ArrayLogger {
res: any[] = [];
log(s: any): void { this.res.push(s); }
logGroup(s: any): void { this.res.push(s); }
logGroupEnd(){};
}
export function main() {
describe('RouteConfig with POJO arguments', () => {
var fakeDoc, el, testBindings;
beforeEach(() => {
fakeDoc = DOM.createHtmlDocument();
el = DOM.createElement('app-cmp', fakeDoc);
DOM.appendChild(fakeDoc.body, el);
var logger = new _ArrayLogger();
var exceptionHandler = new ExceptionHandler(logger, true);
testBindings = [
ROUTER_BINDINGS,
bind(LocationStrategy).toClass(MockLocationStrategy),
bind(DOCUMENT).toValue(fakeDoc),
bind(ExceptionHandler).toValue(exceptionHandler)
];
});
it('should bootstrap an app with a hierarchy', inject([AsyncTestCompleter], (async) => {
bootstrap(HierarchyAppCmp, testBindings)
.then((applicationRef) => {
var router = applicationRef.hostComponent.router;
router.subscribe((_) => {
expect(el).toHaveText('root { parent { hello } }');
expect(applicationRef.hostComponent.location.path()).toEqual('/parent/child');
async.done();
});
router.navigate('/parent/child');
});
}), 1000);
from angular-seed.
Couldn't get the above working.....same darn binding error...DI doesn't see the router.
from angular-seed.
I've added support for unit test using router in test_router branch (home component). Import part is still maybe to be cleaned-up.
from angular-seed.
Hi,
So far working fine. Really appreciate your time. Sometimes we/I really need a direction; as you know plowing through source code can take a quite a bit of time. I was close, but was looking at bootstrapping the router, but honestly I was not sure of how all the pieces went together. For example, I was having problems with the location. Also, I didn't realize that ROUTER_DIRECTIVES had to be a part of the actual about.ts file (I was trying to put them in the dummy spec component).
For others reading this, this is a nice link which discusses the above solution although ludohenin (Ludovic Henin) does a nice job at putting it all together in the testing framework. The link --> http://blog.thoughtram.io/angular/2015/06/16/routing-in-angular-2.html
from angular-seed.
Related Issues (20)
- An in-range update of yargs is breaking the build 🚨 HOT 1
- An in-range update of autoprefixer is breaking the build 🚨 HOT 1
- An in-range update of gulp-tslint is breaking the build 🚨 HOT 1
- An in-range update of rollup-plugin-node-resolve is breaking the build 🚨 HOT 1
- An in-range update of @types/node is breaking the build 🚨 HOT 1
- An in-range update of rollup-plugin-commonjs is breaking the build 🚨 HOT 1
- An in-range update of browserslist is breaking the build 🚨 HOT 1
- An in-range update of autoprefixer is breaking the build 🚨 HOT 1
- Problem with build.prod HOT 1
- An in-range update of @types/node is breaking the build 🚨 HOT 2
- An in-range update of through2 is breaking the build 🚨 HOT 1
- An in-range update of @compodoc/compodoc is breaking the build 🚨 HOT 1
- An in-range update of gulp-uglify is breaking the build 🚨 HOT 1
- problem after importing ngx-bootstrap module
- Message
- node_modules/@nguniversal/express-engine/tokens.js 404 (Not Found) HOT 1
- How to Run Codelyzer and How to Solve Angular-Seed
- App does not load with ngrok HOT 1
- aq
- node . node:internal/modules/cjs/loader:1075 throw err; ^ Error: Cannot find module 'C:\Users\Jan Duszak\Desktop\FiveM-Status-Discord-Bot-main\node_modules' at Module._resolveFilename (node:internal/modules/cjs/loader:1072:15) at Module._load (node:internal/modules/cjs/loader:925:27) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12) at node:internal/main/run_main_module:23:47 { code: 'MODULE_NOT_FOUND', requireStack: [] } Node.js v20.3.1 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-seed.