Skip to content

Commit

Permalink
test: add test cases for async and done
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion committed Jan 20, 2020
1 parent 85b791f commit 0576164
Showing 1 changed file with 39 additions and 18 deletions.
57 changes: 39 additions & 18 deletions example/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { NoopAnimationsModule } from "@angular/platform-browser/animations";
import {
async,
fakeAsync,
tick,
ComponentFixture,
} from '@angular/core/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
ComponentFixture
} from "@angular/core/testing";
import { NO_ERRORS_SCHEMA } from "@angular/core";

import { ConfigureFn, configureTests } from '@lib/testing';
import { ConfigureFn, configureTests } from "@lib/testing";

import { AppComponent } from './app.component';
import { AppComponent } from "./app.component";

describe('AppComponent', () => {
describe("AppComponent", () => {
let fixture: ComponentFixture<AppComponent>;
let component: AppComponent;

Expand All @@ -20,7 +20,7 @@ describe('AppComponent', () => {
testBed.configureTestingModule({
declarations: [AppComponent],
imports: [NoopAnimationsModule],
schemas: [NO_ERRORS_SCHEMA],
schemas: [NO_ERRORS_SCHEMA]
});
};

Expand All @@ -31,27 +31,28 @@ describe('AppComponent', () => {
});
}));

it('should create the app', async(() => {
it("should create the app", async(() => {
const app = component;
expect(app).toBeTruthy();
}));

it('snaps', () => {
it("snaps", () => {
expect(fixture).toMatchSnapshot();
});

it(`should have as title 'app works!'`, async(() => {
const app = component;
expect(app.title).toEqual('app works!');
expect(app.title).toEqual("app works!");
}));

it('should render title in a h1 tag', async(() => {
it("should render title in a h1 tag", async(() => {
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('app works!');
expect(compiled.querySelector("h1").textContent).toContain("app works!");
}));

it('looks async but is synchronous', <any>fakeAsync(
(): void => {
it(
"looks async but is synchronous",
<any>fakeAsync((): void => {
let flag = false;
setTimeout(() => {
flag = true;
Expand All @@ -61,8 +62,28 @@ describe('AppComponent', () => {
expect(flag).toBe(false);
tick(50);
expect(flag).toBe(true);
}
));
})
);

it(
"async should work",
<any>async((): void => {
let flag = false;
setTimeout(() => {
flag = true;
expect(flag).toBe(true);
}, 100);
})
);

it("test with done should work", (done): void => {
let flag = false;
setTimeout(() => {
flag = true;
expect(flag).toBe(true);
done();
}, 100);
});
});

test.todo('a sample todo');
test.todo("a sample todo");

0 comments on commit 0576164

Please sign in to comment.