| 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 ) |
| 19 class LogAttrDirective implements NgAttachAware { | 20 class LogAttrDirective implements NgAttachAware { |
| 20 final Logger log; | 21 final Logger log; |
| 21 String logMessage; | 22 String logMessage; |
| 22 LogAttrDirective(this.log); | 23 LogAttrDirective(this.log); |
| 23 void attach() { | 24 attach() => log(logMessage == '' ? 'LOG' : logMessage); |
| 24 log(logMessage == '' ? 'LOG' : logMessage); | |
| 25 } | |
| 26 } | 25 } |
| 27 | 26 |
| 28 /** | 27 /** |
| 29 * A convenient way to verify that a set of operations executed in a specific | 28 * A convenient way to verify that a set of operations executed in a specific |
| 30 * order. Simply inject the Logger into each operation and call: | 29 * order. Simply inject the Logger into each operation and call: |
| 31 * | 30 * |
| 32 * operation1(Logger logger) => logger('foo'); | 31 * operation1(Logger logger) => logger('foo'); |
| 33 * operation2(Logger logger) => logger('bar'); | 32 * operation2(Logger logger) => logger('bar'); |
| 34 * | 33 * |
| 35 * Then in the test: | 34 * Then in the test: |
| 36 * | 35 * |
| 37 * expect(logger).toEqual(['foo', 'bar']); | 36 * expect(logger).toEqual(['foo', 'bar']); |
| 38 */ | 37 */ |
| 39 class Logger extends ListBase { | 38 class Logger extends ListBase { |
| 40 final tokens = []; | 39 final List tokens = []; |
| 41 | 40 |
| 42 /** | 41 /** |
| 43 * Add string token to the list. | 42 * Add string token to the list. |
| 44 */ | 43 */ |
| 45 void call(text) { | 44 call(dynamic text) => tokens.add(text); |
| 46 tokens.add(text); | |
| 47 } | |
| 48 | 45 |
| 49 /** | 46 /** |
| 50 * Return a `;` separated list of recorded tokens. | 47 * Return a `;` separated list of recorded tokens. |
| 51 */ | 48 */ |
| 52 String result() => tokens.join('; '); | 49 String result() => tokens.join('; '); |
| 53 | 50 |
| 54 | 51 |
| 55 int get length => tokens.length; | 52 int get length => tokens.length; |
| 56 | 53 |
| 57 operator [](int index) => tokens[index]; | 54 operator [](int index) => tokens[index]; |
| 58 | 55 |
| 59 void operator []=(int index, value) { | 56 void operator []=(int index, value) { tokens[index] = value; } |
| 60 tokens[index] = value; | |
| 61 } | |
| 62 | 57 |
| 63 void set length(int newLength) { | 58 void set length(int newLength) { tokens.length = newLength; } |
| 64 tokens.length = newLength; | |
| 65 } | |
| 66 } | 59 } |
| OLD | NEW |