title: How to test navigation via Navigator in Flutter
body: <p>Let's say, I have a test for a screen in Flutter using <code>WidgetTester</code>. There is a button, which executes a navigation via <code>Navigator</code>. I would like to test behavior of that button. </p>
  
  <p><strong>Widget/Screen</strong></p>
  
  <pre><code>class MyScreen extends StatefulWidget {
  
    MyScreen({Key key}) : super(key: key);
  
    @override
    _MyScreenState createState() =&gt; _MyScreenScreenState();
  }
  
  class _MyScreenState extends State&lt;MyScreen&gt; {
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
          body: Center(
              child: RaisedButton(
                  onPressed: () {
                      Navigator.of(context).pushNamed("/nextscreen");
                  },
                  child: Text(Strings.traktTvUrl)
              )
          )
      );
    }
  
  }
  </code></pre>
  
  <p><strong>Test</strong></p>
  
  <pre><code>void main() {
  
    testWidgets('Button is present and triggers navigation after tapped',
        (WidgetTester tester) async {
      await tester.pumpWidget(MaterialApp(home: MyScreen()));
      expect(find.byType(RaisedButton), findsOneWidget);
      await tester.tap(find.byType(RaisedButton));
      //how to test navigator?    
    });
  }
  </code></pre>
  
  <p>I there a proper way how to check, that Navigator was called? Or is there a way to mock and replace navigator?</p>
  
  <p>Pleas note, that code above will actually fail with an exception, because there is no named route <code>'/nextscreen'</code> declared in application. That's simple to solve and you don't need to point it out.</p>
  
  <p>My main concern is how to correctly approach this test scenario in Flutter.</p>