| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * A library for writing dart unit tests. | 6 * A library for writing dart unit tests. |
| 7 * | 7 * |
| 8 * To import this library, specify the relative path to | 8 * To import this library, specify the relative path to |
| 9 * pkg/unittest/unittest.dart. | 9 * pkg/unittest/unittest.dart. |
| 10 * | 10 * |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 * }); | 68 * }); |
| 69 * } | 69 * } |
| 70 * | 70 * |
| 71 * Asynchronous tests: if callbacks expect between 0 and 2 positional arguments, | 71 * Asynchronous tests: if callbacks expect between 0 and 2 positional arguments, |
| 72 * depending on the suffix of expectAsyncX(). expectAsyncX() will wrap a | 72 * depending on the suffix of expectAsyncX(). expectAsyncX() will wrap a |
| 73 * function into a new callback and will not consider the test complete until | 73 * function into a new callback and will not consider the test complete until |
| 74 * that callback is run. A count argument can be provided to specify the number | 74 * that callback is run. A count argument can be provided to specify the number |
| 75 * of times the callback should be called (the default is 1). | 75 * of times the callback should be called (the default is 1). |
| 76 * | 76 * |
| 77 * #import('path-to-dart/pkg/unittest/unitest.dart'); | 77 * #import('path-to-dart/pkg/unittest/unitest.dart'); |
| 78 * #import('dart:html'); | 78 * #import('dart:dom_deprecated'); |
| 79 * main() { | 79 * main() { |
| 80 * test('calllback is executed once', () { | 80 * test('calllback is executed once', () { |
| 81 * // wrap the callback of an asynchronous call with [expectAsync0] if | 81 * // wrap the callback of an asynchronous call with [expectAsync0] if |
| 82 * // the callback takes 0 arguments... | 82 * // the callback takes 0 arguments... |
| 83 * window.setTimeout(expectAsync0(() { | 83 * window.setTimeout(expectAsync0(() { |
| 84 * int x = 2 + 3; | 84 * int x = 2 + 3; |
| 85 * expect(x, equals(5)); | 85 * expect(x, equals(5)); |
| 86 * }), 0); | 86 * }), 0); |
| 87 * }); | 87 * }); |
| 88 * | 88 * |
| (...skipping 20 matching lines...) Expand all Loading... |
| 109 * future, we plan to expose a single `expectAsync` function that can be used | 109 * future, we plan to expose a single `expectAsync` function that can be used |
| 110 * regardless of the number of positional arguments. This requires new langauge | 110 * regardless of the number of positional arguments. This requires new langauge |
| 111 * features or fixes to the current spec (e.g. see | 111 * features or fixes to the current spec (e.g. see |
| 112 * [Issue 2706](http://dartbug.com/2706)). | 112 * [Issue 2706](http://dartbug.com/2706)). |
| 113 * | 113 * |
| 114 * Meanwhile, we plan to add this alternative API for callbacks of more than 2 | 114 * Meanwhile, we plan to add this alternative API for callbacks of more than 2 |
| 115 * arguments or that take named parameters. (this is not implemented yet, | 115 * arguments or that take named parameters. (this is not implemented yet, |
| 116 * but will be coming here soon). | 116 * but will be coming here soon). |
| 117 * | 117 * |
| 118 * #import('path-to-dart/pkg/unittest/unitest.dart'); | 118 * #import('path-to-dart/pkg/unittest/unitest.dart'); |
| 119 * #import('dart:html'); | 119 * #import('dart:dom_deprecated'); |
| 120 * main() { | 120 * main() { |
| 121 * test('calllback is executed', () { | 121 * test('calllback is executed', () { |
| 122 * // indicate ahead of time that an async callback is expected. | 122 * // indicate ahead of time that an async callback is expected. |
| 123 * var async = startAsync(); | 123 * var async = startAsync(); |
| 124 * window.setTimeout(() { | 124 * window.setTimeout(() { |
| 125 * // Guard the body of the callback, so errors are propagated | 125 * // Guard the body of the callback, so errors are propagated |
| 126 * // correctly | 126 * // correctly |
| 127 * guardAsync(() { | 127 * guardAsync(() { |
| 128 * int x = 2 + 3; | 128 * int x = 2 + 3; |
| 129 * expect(x, equals(5)); | 129 * expect(x, equals(5)); |
| (...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 } | 864 } |
| 865 | 865 |
| 866 /** Enable a test by ID. */ | 866 /** Enable a test by ID. */ |
| 867 void enableTest(int testId) => _setTestEnabledState(testId, true); | 867 void enableTest(int testId) => _setTestEnabledState(testId, true); |
| 868 | 868 |
| 869 /** Disable a test by ID. */ | 869 /** Disable a test by ID. */ |
| 870 void disableTest(int testId) => _setTestEnabledState(testId, false); | 870 void disableTest(int testId) => _setTestEnabledState(testId, false); |
| 871 | 871 |
| 872 /** Signature for a test function. */ | 872 /** Signature for a test function. */ |
| 873 typedef void TestFunction(); | 873 typedef void TestFunction(); |
| OLD | NEW |