| OLD | NEW |
| 1 part of angular.mock; | 1 part of angular.mock; |
| 2 | 2 |
| 3 /** | 3 /** |
| 4 * A convenient way to assert the order in which the DOM elements are processed. | 4 * A convenient way to assert the order in which the DOM elements are processed. |
| 5 * | 5 * |
| 6 * In your test create: | 6 * In your test create: |
| 7 * | 7 * |
| 8 * <div log="foo">...</div> | 8 * <div log="foo">...</div> |
| 9 * | 9 * |
| 10 * And then assert: | 10 * And then assert: |
| 11 * | 11 * |
| 12 * expect(logger).toEqual(['foo']); | 12 * expect(logger).toEqual(['foo']); |
| 13 */ | 13 */ |
| 14 @NgDirective( | 14 @NgDirective( |
| 15 selector: '[log]', | 15 selector: '[log]', |
| 16 map: const { | 16 map: const { |
| 17 'log': '@logMessage' | 17 'log': '@logMessage' |
| 18 } | 18 }) |
| 19 ) | |
| 20 class LogAttrDirective implements NgAttachAware { | 19 class LogAttrDirective implements NgAttachAware { |
| 21 final Logger log; | 20 final Logger log; |
| 22 String logMessage; | 21 String logMessage; |
| 23 LogAttrDirective(this.log); | 22 LogAttrDirective(this.log); |
| 24 attach() => log(logMessage == '' ? 'LOG' : logMessage); | 23 void attach() { |
| 24 log(logMessage == '' ? 'LOG' : logMessage); |
| 25 } |
| 25 } | 26 } |
| 26 | 27 |
| 27 /** | 28 /** |
| 28 * A convenient way to verify that a set of operations executed in a specific | 29 * A convenient way to verify that a set of operations executed in a specific |
| 29 * order. Simply inject the Logger into each operation and call: | 30 * order. Simply inject the Logger into each operation and call: |
| 30 * | 31 * |
| 31 * operation1(Logger logger) => logger('foo'); | 32 * operation1(Logger logger) => logger('foo'); |
| 32 * operation2(Logger logger) => logger('bar'); | 33 * operation2(Logger logger) => logger('bar'); |
| 33 * | 34 * |
| 34 * Then in the test: | 35 * Then in the test: |
| 35 * | 36 * |
| 36 * expect(logger).toEqual(['foo', 'bar']); | 37 * expect(logger).toEqual(['foo', 'bar']); |
| 37 */ | 38 */ |
| 38 class Logger extends ListBase { | 39 class Logger extends ListBase { |
| 39 final List tokens = []; | 40 final tokens = []; |
| 40 | 41 |
| 41 /** | 42 /** |
| 42 * Add string token to the list. | 43 * Add string token to the list. |
| 43 */ | 44 */ |
| 44 call(dynamic text) => tokens.add(text); | 45 void call(text) { |
| 46 tokens.add(text); |
| 47 } |
| 45 | 48 |
| 46 /** | 49 /** |
| 47 * Return a `;` separated list of recorded tokens. | 50 * Return a `;` separated list of recorded tokens. |
| 48 */ | 51 */ |
| 49 String result() => tokens.join('; '); | 52 String result() => tokens.join('; '); |
| 50 | 53 |
| 51 | 54 |
| 52 int get length => tokens.length; | 55 int get length => tokens.length; |
| 53 | 56 |
| 54 operator [](int index) => tokens[index]; | 57 operator [](int index) => tokens[index]; |
| 55 | 58 |
| 56 void operator []=(int index, value) { tokens[index] = value; } | 59 void operator []=(int index, value) { |
| 60 tokens[index] = value; |
| 61 } |
| 57 | 62 |
| 58 void set length(int newLength) { tokens.length = newLength; } | 63 void set length(int newLength) { |
| 64 tokens.length = newLength; |
| 65 } |
| 59 } | 66 } |
| OLD | NEW |