isolates_test.dart 793 Bytes
Newer Older
1 2 3 4
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
@TestOn('!chrome') // isolates not supported on the web.

7 8 9 10 11 12 13 14 15 16 17 18
import 'package:flutter/foundation.dart';

import '../flutter_test_alternative.dart';

int test1(int value) {
  return value + 1;
}

int test2(int value) {
  throw 2;
}

19 20 21 22 23 24 25 26
Future<int> test1Async(int value) async {
  return value + 1;
}

Future<int> test2Async(int value) async {
  throw 2;
}

27 28 29 30
void main() {
  test('compute()', () async {
    expect(await compute(test1, 0), 1);
    expect(compute(test2, 0), throwsA(isInstanceOf<Exception>()));
31 32 33

    expect(await compute(test1Async, 0), 1);
    expect(compute(test2Async, 0), throwsA(isInstanceOf<Exception>()));
34 35
  });
}