小编Den*_* B.的帖子

Angular2 - 在测试中模拟RouteParams

我在为Angular2组件的测试中为RouteParams依赖项注入模拟时遇到了一些麻烦.我的一般想法是,我可能会错过一些提供者.

测试失败了:

Cannot resolve all parameters for 'RouteParams'(?). Make sure that all the parameters are decorated with Inject
or have valid type annotations and that 'RouteParams' is decorated with Injectable.

有谁知道问题可能是什么?

import {
  it,
  inject,
  injectAsync,
  describe,
  beforeEach,
  beforeEachProviders,
  TestComponentBuilder
} from 'angular2/testing';

import {Component, provide} from 'angular2/core';
import {BaseRequestOptions, Http} from 'angular2/http';
import {MockBackend} from 'angular2/http/testing';
import {RouteParams, ROUTER_PROVIDERS, ROUTER_PRIMARY_COMPONENT} from 'angular2/router';

// Load the implementations that should be tested
import {Home} from './home';
import {Title} from './providers/title';

describe('Home', …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing typescript angular2-routing angular

9
推荐指数
2
解决办法
2435
查看次数

angular2-template-loader无法内联组件模板

我正在关注Angpack 2的Webpack上的入门教程:https://angular.io/docs/ts/latest/guide/webpack.html

完成所有步骤后,我在尝试加载应用程序组件的模板时收到404错误.

该教程清楚地指出app.component.html和app.component.css应该由angular2-template-loader动态进行Bundeled,但它们不是,因为浏览器试图通过XHR请求它们.

本教程中的app.compnent.ts代码:

import { Component } from '@angular/core';
import '../../public/css/styles.css';
@Component({
    selector: 'my-app',
    templateUrl: 'app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent { }
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

如果我指定相对于基本路径的模板路径,它可以工作,但这不是正确的方法.

import { Component } from '@angular/core';
import '../../public/css/styles.css';
@Component({
    selector: 'my-app',
    templateUrl: './src/app/app.component.html',
    styleUrls: ['./src/app/app.component.css']
})
export class AppComponent { }
Run Code Online (Sandbox Code Playgroud)

有没有人知道为什么会这样,有人能够用一个有效的解决方案完成教程吗?

webpack angular

6
推荐指数
1
解决办法
1590
查看次数