本文整理汇总了TypeScript中angular2/src/test_lib/test_bed.TestBed类的典型用法代码示例。如果您正苦于以下问题:TypeScript TestBed类的具体用法?TypeScript TestBed怎么用?TypeScript TestBed使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestBed类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: inject
inject([TestBed, AsyncTestCompleter], (tb: TestBed, async) => {
var html =
'<div>' +
'<copy-me template="ng-if numberCondition + 1 >= 2">helloNumber</copy-me>' +
'<copy-me template="ng-if stringCondition == \'foo\'">helloString</copy-me>' +
'<copy-me template="ng-if functionCondition(stringCondition, numberCondition)">helloFunction</copy-me>' +
'</div>';
tb.createView(TestComponent, {html: html})
.then((view) => {
view.detectChanges();
expect(DOM.querySelectorAll(view.rootNodes[0], 'copy-me').length).toEqual(3);
expect(DOM.getText(view.rootNodes[0]))
.toEqual('helloNumberhelloStringhelloFunction');
view.context.numberCondition = 0;
view.detectChanges();
expect(DOM.querySelectorAll(view.rootNodes[0], 'copy-me').length).toEqual(1);
expect(DOM.getText(view.rootNodes[0])).toEqual('helloString');
view.context.numberCondition = 1;
view.context.stringCondition = "bar";
view.detectChanges();
expect(DOM.querySelectorAll(view.rootNodes[0], 'copy-me').length).toEqual(1);
expect(DOM.getText(view.rootNodes[0])).toEqual('helloNumber');
async.done();
});
}));
示例2: inject
inject([TestBed, AsyncTestCompleter], (tb: TestBed, async) => {
var template = '<ul><li template="ng-for #item of items">{{item["name"]}};</li></ul>';
tb.createView(TestComponent, {html: template})
.then((view) => {
// INIT
view.context.items = [{'name': 'misko'}, {'name': 'shyam'}];
view.detectChanges();
expect(DOM.getText(view.rootNodes[0])).toEqual('misko;shyam;');
// GROW
ListWrapper.push(view.context.items, {'name': 'adam'});
view.detectChanges();
expect(DOM.getText(view.rootNodes[0])).toEqual('misko;shyam;adam;');
// SHRINK
ListWrapper.removeAt(view.context.items, 2);
ListWrapper.removeAt(view.context.items, 0);
view.detectChanges();
expect(DOM.getText(view.rootNodes[0])).toEqual('shyam;');
async.done();
});
}));
示例3: inject
inject([TestBed, AsyncTestCompleter], (tb: TestBed, async) => {
var template = '<div>' +
'<ul [ng-switch]="switchValue">' +
'<template [ng-switch-when]="\'a\'"><li>when a1;</li></template>' +
'<template [ng-switch-when]="\'b\'"><li>when b1;</li></template>' +
'<template [ng-switch-when]="\'a\'"><li>when a2;</li></template>' +
'<template [ng-switch-when]="\'b\'"><li>when b2;</li></template>' +
'<template ng-switch-default><li>when default1;</li></template>' +
'<template ng-switch-default><li>when default2;</li></template>' +
'</ul></div>';
tb.createView(TestComponent, {html: template})
.then((view) => {
view.detectChanges();
expect(DOM.getText(view.rootNodes[0])).toEqual('when default1;when default2;');
view.context.switchValue = 'a';
view.detectChanges();
expect(DOM.getText(view.rootNodes[0])).toEqual('when a1;when a2;');
view.context.switchValue = 'b';
view.detectChanges();
expect(DOM.getText(view.rootNodes[0])).toEqual('when b1;when b2;');
async.done();
});
}));
示例4: inject
inject([TestBed, AsyncTestCompleter], (tb: TestBed, async) => {
var template = '<div>{{text}}<span ng-non-bindable>{{text}}</span></div>';
tb.createView(TestComponent, {html: template})
.then((view) => {
view.detectChanges();
expect(DOM.getText(view.rootNodes[0])).toEqual('foo{{text}}');
async.done();
});
}));