| 24 | jasmine.addMatchers({ |
| 25 | toBeAHero: () => ({ |
| 26 | compare(actualNg1Hero: ElementFinder | undefined) { |
| 27 | const getText = (selector: string) => actualNg1Hero!.element(by.css(selector)).getText(); |
| 28 | const result = { |
| 29 | message: 'Expected undefined to be an `ng1Hero` ElementFinder.', |
| 30 | pass: |
| 31 | !!actualNg1Hero && |
| 32 | Promise.all(['.title', 'h2', 'p'].map(getText) as PromiseLike<string>[]).then( |
| 33 | ([actualTitle, actualName, actualDescription]) => { |
| 34 | const pass = |
| 35 | actualTitle === 'Super Hero' && |
| 36 | isTitleCased(actualName) && |
| 37 | actualDescription.length > 0; |
| 38 | |
| 39 | const actualHero = `Hero(${actualTitle}, ${actualName}, ${actualDescription})`; |
| 40 | result.message = `Expected ${actualHero}'${pass ? ' not' : ''} to be a real hero.`; |
| 41 | |
| 42 | return pass; |
| 43 | }, |
| 44 | ), |
| 45 | }; |
| 46 | return result; |
| 47 | }, |
| 48 | }), |
| 49 | toHaveName: () => ({ |
| 50 | compare(actualNg1Hero: ElementFinder | undefined, expectedName: string) { |