Html 空输入字段
我正在表单字段的弹出窗口中加载数据。当我运行它时,输入区域被一个正确的字符串填充,但是当我尝试测试它时,它是空的“”。测试期间未使用服务 HTMLHtml 空输入字段,html,angular,typescript,jasmine,karma-jasmine,Html,Angular,Typescript,Jasmine,Karma Jasmine,我正在表单字段的弹出窗口中加载数据。当我运行它时,输入区域被一个正确的字符串填充,但是当我尝试测试它时,它是空的“”。测试期间未使用服务 HTML })) 不要显式实例化您的BankDetailsComponent类,而是让@angular/core/testing中的TestBed为您编译并创建它。这通常在每个块之前的中完成 import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { B
})) 不要显式实例化您的
BankDetailsComponent
类,而是让@angular/core/testing
中的TestBed
为您编译并创建它。这通常在每个块之前的中完成
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { BankDetailsComponent } from './bank-details.component';
describe('BankDetailsComponent', () => {
let component: BankDetailsComponent;
let fixture: ComponentFixture<BankDetailsComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ BankDetailsComponent ],
imports: [...],
providers: [...]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(BankDetailsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should get receiver currency Xpath', () => {
...
});
});
从'@angular/core/testing'导入{async,ComponentFixture,TestBed};
从“./bank details.component”导入{BankDetailsComponent};
描述('BankDetailsComponent',()=>{
let组件:bankDetails组件;
let夹具:组件夹具;
beforeach(异步(()=>{
TestBed.configureTestingModule({
声明:[BankDetailsComponent],
进口:[……],
提供者:[……]
})
.compileComponents();
}));
在每个之前(()=>{
fixture=TestBed.createComponent(BankDetailsComponent);
组件=fixture.componentInstance;
fixture.detectChanges();
});
它('should get receiver currency Xpath',()=>{
...
});
});
有关更多详情,请咨询
bank = {
name: 'Nordea',
country: 'DK',
pageurl: 'http://n.dk',
buyxpath: 'abc',
sellxpath: 'abc',
fromCurrency: 'abc',
toCurrencyXpath: 'abc',
unit: 'M100',
id: 'abc',
};
it('should get receiver currency Xpath', () => {
const detComponent = new BankDetailsComponent(service, bank, fb, dialog);
fixture.whenStable();
fixture.detectChanges();
console.log(detComponent.name); //reads the value of the class variable
const currency: HTMLElement = fixture.debugElement.query(By.css('#toCurrencyXpath')).nativeElement;
fixture.whenStable();
fixture.detectChanges();
expect(currency.textContent).toBe('abc'); //Expected '' to be 'abc'.
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { BankDetailsComponent } from './bank-details.component';
describe('BankDetailsComponent', () => {
let component: BankDetailsComponent;
let fixture: ComponentFixture<BankDetailsComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ BankDetailsComponent ],
imports: [...],
providers: [...]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(BankDetailsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should get receiver currency Xpath', () => {
...
});
});