Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit de4f0d1

Browse files
committed
feat: tests for with-ajax component
1 parent b69d488 commit de4f0d1

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* tslint:disable:no-unused-variable */
2+
3+
import { RouterTestingModule } from '@angular/router/testing';
4+
import { HttpClientModule } from '@angular/common/http';
5+
import { SecurityContext } from '@angular/core';
6+
import { TestBed, waitForAsync } from '@angular/core/testing';
7+
import { DataTableDirective, DataTablesModule } from 'angular-datatables';
8+
import { MarkdownModule } from 'ngx-markdown';
9+
import { BaseDemoComponent } from '../base-demo/base-demo.component';
10+
import { WithAjaxComponent } from './with-ajax.component';
11+
import { AppRoutingModule } from '../app.routing';
12+
13+
describe('WithAjaxComponent', () => {
14+
beforeEach(() => {
15+
TestBed.configureTestingModule({
16+
declarations: [
17+
BaseDemoComponent,
18+
WithAjaxComponent,
19+
DataTableDirective
20+
],
21+
imports: [
22+
AppRoutingModule,
23+
RouterTestingModule,
24+
DataTablesModule,
25+
HttpClientModule,
26+
MarkdownModule.forRoot(
27+
{
28+
sanitize: SecurityContext.NONE
29+
}
30+
)
31+
]
32+
}).compileComponents();
33+
});
34+
35+
it('should create the app', waitForAsync(() => {
36+
const fixture = TestBed.createComponent(WithAjaxComponent);
37+
const app = fixture.debugElement.componentInstance;
38+
expect(app).toBeTruthy();
39+
}));
40+
41+
it('should have title "With Ajax"', waitForAsync(() => {
42+
const fixture = TestBed.createComponent(WithAjaxComponent);
43+
const app = fixture.debugElement.componentInstance as WithAjaxComponent;
44+
expect(app.pageTitle).toBe('With Ajax');
45+
}));
46+
47+
it('should have table populated via AJAX', waitForAsync(() => {
48+
const fixture = TestBed.createComponent(WithAjaxComponent);
49+
const app = fixture.debugElement.componentInstance as WithAjaxComponent;
50+
expect(app.dtOptions.columns).toBeFalsy();
51+
// trigger change detection
52+
fixture.detectChanges();
53+
expect(app.dtOptions.columns).toBeDefined();
54+
55+
// check table is populated
56+
setTimeout(() => {
57+
expect($('#preview table tbody').children().length).toBeGreaterThan(0);
58+
}, 700);
59+
}));
60+
61+
});

0 commit comments

Comments
 (0)