Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/cdk/testing/tests/testbed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,12 @@ describe('TestbedHarnessEnvironment', () => {
});

describe('harness', () => {
let harness: MainComponentHarness;

beforeEach(async () => {
harness = await TestbedHarnessEnvironment.harnessForFixture(
fixture,
MainComponentHarness,
);
});
function getHarness() {
return TestbedHarnessEnvironment.harnessForFixture(fixture, MainComponentHarness);
}

it('can get elements outside of host', async () => {
const harness = await getHarness();
const subcomponents = await harness.allLists();
expect(subcomponents[0]).not.toBeNull();
const globalEl = await subcomponents[0]!.globalElement();
Expand All @@ -80,23 +76,29 @@ describe('TestbedHarnessEnvironment', () => {
});

it('should be able to wait for tasks outside of Angular within native async/await', async () => {
const harness = await getHarness();
expect(await harness.getTaskStateResult()).toBe('result');
});

it('should be able to wait for tasks outside of Angular within async test zone', waitForAsync(() => {
it('should be able to wait for tasks outside of Angular within async test zone', waitForAsync(async () => {
const harness = await getHarness();
harness.getTaskStateResult().then(res => expect(res).toBe('result'));
}));

it('should be able to wait for tasks outside of Angular within fakeAsync test zone', fakeAsync(async () => {
const harness = await getHarness();

expect(await harness.getTaskStateResult()).toBe('result');
}));

it('should be able to retrieve the native DOM element from a UnitTestElement', async () => {
const harness = await getHarness();
const element = TestbedHarnessEnvironment.getNativeElement(await harness.host());
expect(element.id).toContain('root');
});

it('should wait for async operation to complete in fakeAsync test', fakeAsync(async () => {
const harness = await getHarness();
const asyncCounter = await harness.asyncCounter();
expect(await asyncCounter.text()).toBe('5');
await harness.increaseCounter(3);
Expand Down
Loading