|
describe('AppComponent', () => {
let fixture: ComponentFixture<AppComponent>;
var originalTimeout;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
imports: [
ListBoxAllModule
]
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
});
it('should create the app', () => {
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
it('getDataList method checking', (done: Function) => {
const app = fixture.componentInstance;
setTimeout(() => {
if (app.isDataBound) {
expect(app.getDataList()[0].FirstName).toBe('Andrew Fuller');
done();
}
}, 1000);
});
it('getSortedList method checking', (done: Function) => {
const app = fixture.componentInstance;
setTimeout(() => {
if (app.isDataBound) {
expect(app.getSortedList()[0].FirstName).toBe("Steven Buchanan");
done();
}
}, 1000);
});
});
|
|
export class AppComponent {
title = 'angular-unit-testing';
@ViewChild('listbox')
public listboxObj: ListBoxComponent;
public data: DataManager = new DataManager({
url: 'https://ej2services.syncfusion.com/production/web-services/api/Employees',
adaptor: new WebApiAdaptor,
crossDomain: true
});
public query: Query = new Query().select(['FirstName', 'EmployeeID']).take(10).requiresCount();
public field: Object = { text:'FirstName',value: 'FirstName' };
public value: string[] = ["Andrew Fuller"];
public isDataBound: boolean = false;
dataBound(args) {
if (args.name === 'dataBound') {
this.isDataBound = true;
}
}
getDataList(): { [key: string]: Object; }[] {
return this.listboxObj.getDataList() as { [key: string]: Object; }[];
}
getSortedList(): { [key: string]: Object; }[] {
return this.listboxObj.getSortedList() as { [key: string]: Object; }[];
}
}
|