Skip to content

Instantly share code, notes, and snippets.

@shailen
Created February 25, 2014 17:46
Show Gist options
  • Save shailen/9214040 to your computer and use it in GitHub Desktop.
Save shailen/9214040 to your computer and use it in GitHub Desktop.
// When to use expectAsync?
import 'package:unittest/unittest.dart';
import 'dart:async';
syncAdd(x, y) => x + y;
asyncAdd(x, y) => new Future.value(x + y);
void main() {
test('testing sync code synchronously', () {
expect(syncAdd(3, 4), 7);
});
test('testing sync code asynchronously', () {
new Future(expectAsync(() {
expect(syncAdd(3, 4), 7);
}));
});
test('testing async code synchronously', () {
asyncAdd(3, 4).then((result) {
expect(result, 7);
});
});
test('testing async code asynchronously', () {
new Future(expectAsync(() {
asyncAdd(3, 4).then((result) {
expect(result, 7);
});
}));
});
test("testing async without expectAsync(). DON'T DO THIS.", () {
new Future(() {
// Test does not run!!!!!!!!
expect(1, 2);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment