[web] Add JS type test for JsStrategy. (flutter/engine#39765)

This commit is contained in:
joshualitt
2023-03-03 10:09:03 -08:00
committed by GitHub
parent d164c4aaef
commit 9defbf1d0b
2 changed files with 13 additions and 2 deletions

View File

@@ -273,8 +273,18 @@ Future<void> _downloadAssetFonts() async {
void _addUrlStrategyListener() {
jsSetUrlStrategy = allowInterop((JsUrlStrategy? jsStrategy) {
customUrlStrategy =
jsStrategy == null ? null : CustomUrlStrategy.fromJs(jsStrategy);
if (jsStrategy == null) {
customUrlStrategy = null;
} else {
// Because `JSStrategy` could be anything, we check for the
// `addPopStateListener` property and throw if it is missing.
if (!hasJsProperty(jsStrategy, 'addPopStateListener')) {
throw StateError(
'Unexpected JsUrlStrategy: $jsStrategy is missing '
'`addPopStateListener` property');
}
customUrlStrategy = CustomUrlStrategy.fromJs(jsStrategy);
}
});
registerHotRestartListener(() {
jsSetUrlStrategy = null;

View File

@@ -435,6 +435,7 @@ void testMain() {
expect(() => jsSetUrlStrategy(123), throwsA(anything));
expect(() => jsSetUrlStrategy('foo'), throwsA(anything));
expect(() => jsSetUrlStrategy(false), throwsA(anything));
expect(() => jsSetUrlStrategy(<Object?>[]), throwsA(anything));
});
test('cannot set url strategy after it is initialized', () async {