我正在尝试测试我的角度4.1.0组件 -
export class CellComponent implements OnInit {
lines: Observable<Array<ILine>>;
@Input() dep: string;
@Input() embedded: boolean;
@Input() dashboard: boolean;
constructor(
public dataService: CellService,
private route: ActivatedRoute,
private router: Router, private store: Store<AppStore>) {
}
}
Run Code Online (Sandbox Code Playgroud)
但是,一个简单的"应该创建"测试会引发这个神秘的错误......
NetworkError:无法在'XMLHttpRequest'上执行'send':无法加载'ng:///DynamicTestModule/module.ngfactory.js'.
所以我发现了这个问题,这表明问题是组件有@Input)_没有设置的参数,但是,如果我像这样修改我的测试:
it('should create', inject([CellComponent], (cmp: CellComponent) => {
cmp.dep = '';
cmp.embedded = false;
cmp.dashboard = false;
expect(cmp).toBeTruthy();
}));
Run Code Online (Sandbox Code Playgroud)
然后我仍然得到相同的问题,同样,如果我@Input()从组件中删除注释,仍然没有区别.我怎样才能通过这些测试?
鉴于以下类,我如何枚举它的属性,即获得类似的输出[station1, station2, station3 ...].我只能看到如何枚举属性的值,即[null, null, null].
class stationGuide {
station1: any;
station2: any;
station3: any;
constructor(){
this.station1 = null;
this.station2 = null;
this.station3 = null;
}
}
Run Code Online (Sandbox Code Playgroud) 我刚刚开始使用Ionic 2.我img在app里面创建了一个文件,它是一个文件logo.png.所以我创建了以下代码:
CSS:
.getting-started {
.logo {
background-image: url(./img/logo.png);
}
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<ion-col offset-33 width-33 class="logo"><h1>Logo</h1></ion-col>
<h3>Welcome to your first Ionic app!</h3>
</ion-content>
Run Code Online (Sandbox Code Playgroud)
我知道css正在工作,好像我切换背景颜色,我得到了预期的结果.但是,我没有得到任何背景图片,只是指定了Logo文本.我应该把图像文件放在哪里?
我想在Windows上开始使用Docker.我的机器有4GB内存和1.9GHz - 2.5GHz Intel i5处理器,运行Windows 10 Pro x64.我知道这些并不是强大的规格,但我原以为我应该可以运行Docker?
但是,下载了Docker后,我收到错误消息:
没有足够的内存来启动docker
我已经看到各种论坛帖子和github问题,并遵循我可以看到的所有建议,例如修改Docker中的设置,我试过这些:
他们还提到了更改Hyper-V VM的设置,但是,这似乎被删除并在每次尝试启动时使用Docker指定的设置重新创建.我尝试了2048MB,1792MB,1536MB,1280MB和1024MB的RAM,所有这些都失败了.
我还可以做些什么?当然我可以在我的机器上以某种形式运行docker?注意:我已关闭所有非必要的后台应用程序.对于什么似乎是一个相当普遍的问题似乎没有很多其他建议,其中给定的解决方案不起作用?
我试图在我的应用程序中单元测试角度服务,这将创建socket.io客户端.我的服务看起来像这样:
export class SocketService {
private name: string;
private host: string = window.location.protocol + "//" + window.location.hostname + ":3000";
socket: io.Socket;
constructor() { }
subscribeEvent(name: string): Observable<IJobResp> {
this.setup(name);
return new Observable(observer => {
this.socket.on('job', val => observer.next(val))
})
}
private setup(name: string) {
this.name = name;
let socketUrl = this.host + "/" + this.name;
this.socket = io.connect(socketUrl);
}
}
Run Code Online (Sandbox Code Playgroud)
所以要编写我的测试,我使用mock-socket库来设置一个mock socket.io服务器.这是测试的样子:
describe('SocketService', () => {
let socket;
const mockServer = new Server('http://localhost:3000/');
mockServer.on('connection', server => {
mockServer.emit('job', 'test message …Run Code Online (Sandbox Code Playgroud) 我@ngrx/store在我的angular(4.x)应用程序中有包,我从v 2.2.2 - > v 4.0.0升级.我可以看到迁移说明说:
已从Action界面中删除有效内容属性.
然而,他们给出的例子似乎完全违反直觉(在我看来......).
我有一个reducer函数,如下所示:
export function titleReducer(state = { company: 'MyCo', site: 'London' }, action: Action): ITitle {
switch (action.type) {
case 'SET_TITLE':
return {
company: action.payload.company,
site: action.payload.site,
department: action.payload.department,
line: action.payload.line
}
case 'RESET':
return {
company: 'MyCo',
site: 'London'
}
default:
return state
}
}
Run Code Online (Sandbox Code Playgroud)
正如预期的那样抛出打字稿错误:
[ts]"行动"类型中不存在属性"有效负载"
但是我从迁移指南中不知道这应该改变什么.有任何想法吗?
当通过URL访问时,我的angular2应用程序的路由不起作用... Express正在呈现错误页面.
所以我有一个route(/docs)提供一些静态内容和一些其他静态资源,然而,/路由到index.html由angular 2管理.所以通过打开应用程序根然后单击各种路由器链接,我可以到达一条路线,例如/tutorial/chapter/1.但是,由于这不是我的快递应用程序中的注册路线,如果我刷新页面,我会得到404.
我希望能够输入http://localhost:3000/tutorial/chapter/1我的浏览器并获取该页面.如何设置express来将所有未定义的路由路由到angular,并让angular处理404?
这是我的app.js:
var app = express();
// html view engine setup
app.set('views', path.join(__dirname, '/ng2/views'));
app.engine('html', require('jade').renderFile);
app.set('view engine', 'html');
app.use(express.static('ng2/views'));
app.use(express.static('ng2/public'));
app.use('/node_modules', express.static(__dirname + '/node_modules'));
// uncomment after placing your favicon in /public
app.use(favicon(path.join(__dirname, 'ng2/public', 'favicon.png')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
//all static assetes for hexo content
app.use('/docs', serveStatic('features/docs/public', { 'index': ['index.html', 'index.htm'] }));
app.use('/', routes);
// catch 404 and forward to error handler …Run Code Online (Sandbox Code Playgroud) 我有一个带角度前端的nodejs api.API成功地使用JWT和护照来保护它的端点.
我现在意识到,在令牌过期后,我的前端仍然允许用户请求我的api端点,而不会提示他们重新输入他们的登录详细信息以获得新的令牌.
这是我的后端生成令牌的方式:
function generateToken(user) {
return jwt.sign(user, secret, {
expiresIn: 10080 // in seconds
});
}
Run Code Online (Sandbox Code Playgroud)
因此,要实现此逻辑,我认为我需要验证JWT令牌客户端.Q1,这是一种明智的做法.
Q2,JWT我使用的库似乎需要一个公钥来使用它的verify()功能.我似乎没有公钥,只有一个秘密,我刚刚组成,所以它不是用一对产生的.我的公钥来自哪里,或者有没有其他方法来验证我的令牌?
这一切似乎都应该是显而易见的,我已经错过了一些东西,如果这是一个愚蠢的问题,请道歉,但我似乎无法找到答案?
我试图在使用angular-material2的组件上编写测试,但是当我将它添加到我的testModule声明时,我得到:
Error: Template parse errors:
'md-card-title' is not a known element:
1. If 'md-card-title' is an Angular component, then verify that it is part of this module.
2. If 'md-card-title' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message.
Run Code Online (Sandbox Code Playgroud)
将MaterialModule添加到声明中会抛出`错误:模块声明的意外模块'MaterialModule'
config/spec-bundle.js中的DynamicTestModule'(第24994行)
这是我的spec文件的样子:
beforeEach(() => TestBed.configureTestingModule({
declarations: [],
providers: [
{ provide: DataService, useValue: mockDataService },
{ provide: ActivatedRoute, useClass: MockActivatedRoute },
{ provide: Router, useValue: mockRouter },
CellViewComponent
]
}));
Run Code Online (Sandbox Code Playgroud)
添加CellViewComponent …
typescript karma-jasmine angular2-testing angular-material2 angular
typescript ×6
angular ×5
node.js ×2
unit-testing ×2
angular-cli ×1
css ×1
docker ×1
express ×1
html ×1
hyper-v ×1
ionic2 ×1
iterator ×1
jasmine ×1
javascript ×1
jwt ×1
ngrx ×1
ngrx-store ×1
passport.js ×1
socket.io ×1
windows ×1