-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bazel): support using es2020 in spec-bundled tests
We currently set the default spec-bundle target to es2016 to work around the ZoneJS async/await native syntax issue. We can default to ES2020 consistently and just downlevel async/await, similar to how the Angular CLI would do it.
- Loading branch information
1 parent
734fd03
commit 07c1c19
Showing
5 changed files
with
111 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'zone.js'; | ||
import 'zone.js/testing'; | ||
|
||
import {JSDOM} from 'jsdom'; | ||
import {Component} from '@angular/core'; | ||
import {fakeAsync, flush, TestBed, waitForAsync} from '@angular/core/testing'; | ||
import { | ||
BrowserDynamicTestingModule, | ||
platformBrowserDynamicTesting, | ||
} from '@angular/platform-browser-dynamic/testing'; | ||
|
||
describe('native async/await downleveled', () => { | ||
beforeAll(() => { | ||
const {window} = new JSDOM(); | ||
|
||
(global as any).window = window; | ||
(global as any).document = window.document; | ||
(global as any).Node = window.Node; | ||
(global as any).MouseEvent = window.MouseEvent; | ||
|
||
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); | ||
}); | ||
|
||
it('should properly detect changes', fakeAsync(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [AppComponent], | ||
}); | ||
const fixture = TestBed.createComponent(AppComponent); | ||
const el = fixture.nativeElement as HTMLElement; | ||
|
||
fixture.detectChanges(); | ||
el.dispatchEvent(new MouseEvent('click')); | ||
fixture.detectChanges(); | ||
|
||
// Flush the timeout macrotask from the click handler. | ||
// Then we attempt detecting changes. | ||
flush(); | ||
fixture.detectChanges(); | ||
|
||
expect(el.textContent).toBe('Yes'); | ||
})); | ||
}); | ||
|
||
@Component({ | ||
selector: 'app-component', | ||
template: `<span>{{ triggered ? 'Yes' : 'No' }}</span>`, | ||
host: { | ||
'(click)': 'click()', | ||
}, | ||
}) | ||
class AppComponent { | ||
triggered = false; | ||
|
||
async click() { | ||
await new Promise((resolve) => setTimeout(resolve, 500)); | ||
this.triggered = true; | ||
} | ||
} |