flutter_js icon indicating copy to clipboard operation
flutter_js copied to clipboard

Exception by xhr

Open glWesley opened this issue 4 years ago • 0 comments

Just a minor issue. In my test project, this exception happened, but everything is ok if close xhr: getJavascriptRuntime(xhr: false):

To test code that needs an HttpClient, provide your own HttpClient
implementation to the code under test, so that your test can
consistently provide a testable response to the code under test.
00:01 +0 -1: js engine basic                                                                                                                                   
Pending timers:
Timer (duration: 0:00:00.040000, periodic: true), created:
#0      new FakeTimer._ (package:fake_async/fake_async.dart:284:41)
#1      FakeAsync._createTimer (package:fake_async/fake_async.dart:248:27)
#2      FakeAsync.run.<anonymous closure> (package:fake_async/fake_async.dart:183:19)
#5      JavascriptRuntimeXhrExtension.enableXhr (package:flutter_js/extensions/xhr.dart:261:11)
#6      JavascriptRuntimeFetchExtension.enableFetch (package:flutter_js/extensions/fetch.dart:12:5)
#7      getJavascriptRuntime (package:flutter_js/flutter_js.dart:42:20)
#8      main.<anonymous closure> (file:///home/wesley/WorkPlace/projects/flutter/begin/test/begin_test.dart:9:20)
#9      main.<anonymous closure> (file:///home/wesley/WorkPlace/projects/flutter/begin/test/begin_test.dart:7:34)
#10     testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:144:29)
<asynchronous suspension>
<asynchronous suspension>
(elided 3 frames from dart:async and package:stack_trace)


══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following assertion was thrown running a test (but after the test had completed):
A Timer is still pending even after the widget tree was disposed.
'package:flutter_test/src/binding.dart':
Failed assertion: line 1241 pos 12: '!timersPending'

When the exception was thrown, this was the stack:
#2      AutomatedTestWidgetsFlutterBinding._verifyInvariants (package:flutter_test/src/binding.dart:1241:12)
#3      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:803:7)
<asynchronous suspension>
(elided 2 frames from class _AssertionError)

create a package begin, and in test/begin_test.dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:flutter_js/flutter_js.dart' as js;

void main() {
  testWidgets('js engine basic', (WidgetTester tester) async {

    final engine = js.getJavascriptRuntime();
    await tester.pumpWidget(MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Builder(builder: (ctx) {
          final result = engine.evaluate("size");
          return Text('size=$result');
        },),
      ),
    );
  });
}

glWesley avatar Apr 19 '21 12:04 glWesley