refactor(docs-infra): fix docs examples for tslint rule prefer-const
(#38143)
This commit updates the docs examples to be compatible with the `prefer-const` tslint rule. This is in preparation of updating the docs examples `tslint.json` to match the one generated for new Angular CLI apps in a future commit. PR Close #38143
This commit is contained in:

committed by
Michael Prentice

parent
a3fe2de883
commit
97ae2d3b9b
@ -13,11 +13,11 @@ describe('Lifecycle hooks', () => {
|
||||
});
|
||||
|
||||
it('should support peek-a-boo', async () => {
|
||||
let pabComp = element(by.css('peek-a-boo-parent peek-a-boo'));
|
||||
const pabComp = element(by.css('peek-a-boo-parent peek-a-boo'));
|
||||
expect(pabComp.isPresent()).toBe(false, 'should not be able to find the "peek-a-boo" component');
|
||||
|
||||
let pabButton = element.all(by.css('peek-a-boo-parent button')).get(0);
|
||||
let updateHeroButton = element.all(by.css('peek-a-boo-parent button')).get(1);
|
||||
const pabButton = element.all(by.css('peek-a-boo-parent button')).get(0);
|
||||
const updateHeroButton = element.all(by.css('peek-a-boo-parent button')).get(1);
|
||||
expect(pabButton.getText()).toContain('Create Peek');
|
||||
|
||||
await pabButton.click();
|
||||
@ -35,12 +35,12 @@ describe('Lifecycle hooks', () => {
|
||||
});
|
||||
|
||||
it('should support OnChanges hook', () => {
|
||||
let onChangesViewEle = element.all(by.css('on-changes div')).get(0);
|
||||
let inputEles = element.all(by.css('on-changes-parent input'));
|
||||
let heroNameInputEle = inputEles.get(1);
|
||||
let powerInputEle = inputEles.get(0);
|
||||
let titleEle = onChangesViewEle.element(by.css('p'));
|
||||
let changeLogEles = onChangesViewEle.all(by.css('div'));
|
||||
const onChangesViewEle = element.all(by.css('on-changes div')).get(0);
|
||||
const inputEles = element.all(by.css('on-changes-parent input'));
|
||||
const heroNameInputEle = inputEles.get(1);
|
||||
const powerInputEle = inputEles.get(0);
|
||||
const titleEle = onChangesViewEle.element(by.css('p'));
|
||||
const changeLogEles = onChangesViewEle.all(by.css('div'));
|
||||
|
||||
expect(titleEle.getText()).toContain('Windstorm can sing');
|
||||
expect(changeLogEles.count()).toEqual(2, 'should start with 2 messages');
|
||||
@ -54,12 +54,12 @@ describe('Lifecycle hooks', () => {
|
||||
});
|
||||
|
||||
it('should support DoCheck hook', async () => {
|
||||
let doCheckViewEle = element.all(by.css('do-check div')).get(0);
|
||||
let inputEles = element.all(by.css('do-check-parent input'));
|
||||
let heroNameInputEle = inputEles.get(1);
|
||||
let powerInputEle = inputEles.get(0);
|
||||
let titleEle = doCheckViewEle.element(by.css('p'));
|
||||
let changeLogEles = doCheckViewEle.all(by.css('div'));
|
||||
const doCheckViewEle = element.all(by.css('do-check div')).get(0);
|
||||
const inputEles = element.all(by.css('do-check-parent input'));
|
||||
const heroNameInputEle = inputEles.get(1);
|
||||
const powerInputEle = inputEles.get(0);
|
||||
const titleEle = doCheckViewEle.element(by.css('p'));
|
||||
const changeLogEles = doCheckViewEle.all(by.css('div'));
|
||||
let logCount: number;
|
||||
|
||||
expect(titleEle.getText()).toContain('Windstorm can sing');
|
||||
@ -82,11 +82,11 @@ describe('Lifecycle hooks', () => {
|
||||
});
|
||||
|
||||
it('should support AfterView hooks', async () => {
|
||||
let parentEle = element(by.tagName('after-view-parent'));
|
||||
let buttonEle = parentEle.element(by.tagName('button')); // Reset
|
||||
let commentEle = parentEle.element(by.className('comment'));
|
||||
let logEles = parentEle.all(by.css('h4 ~ div'));
|
||||
let childViewInputEle = parentEle.element(by.css('app-child-view input'));
|
||||
const parentEle = element(by.tagName('after-view-parent'));
|
||||
const buttonEle = parentEle.element(by.tagName('button')); // Reset
|
||||
const commentEle = parentEle.element(by.className('comment'));
|
||||
const logEles = parentEle.all(by.css('h4 ~ div'));
|
||||
const childViewInputEle = parentEle.element(by.css('app-child-view input'));
|
||||
let logCount: number;
|
||||
|
||||
expect(childViewInputEle.getAttribute('value')).toContain('Magneta');
|
||||
@ -99,7 +99,7 @@ describe('Lifecycle hooks', () => {
|
||||
expect(commentEle.isPresent()).toBe(true, 'should have comment because >10 chars');
|
||||
expect(commentEle.getText()).toContain('long name');
|
||||
|
||||
let count = await logEles.count();
|
||||
const count = await logEles.count();
|
||||
expect(logCount + 7).toBeGreaterThan(count - 3, '7 additional log messages should have been added');
|
||||
expect(logCount + 7).toBeLessThan(count + 3, '7 additional log messages should have been added');
|
||||
|
||||
@ -109,18 +109,18 @@ describe('Lifecycle hooks', () => {
|
||||
});
|
||||
|
||||
it('should support AfterContent hooks', async () => {
|
||||
let parentEle = element(by.tagName('after-content-parent'));
|
||||
let buttonEle = parentEle.element(by.tagName('button')); // Reset
|
||||
let commentEle = parentEle.element(by.className('comment'));
|
||||
let logEles = parentEle.all(by.css('h4 ~ div'));
|
||||
let childViewInputEle = parentEle.element(by.css('app-child input'));
|
||||
const parentEle = element(by.tagName('after-content-parent'));
|
||||
const buttonEle = parentEle.element(by.tagName('button')); // Reset
|
||||
const commentEle = parentEle.element(by.className('comment'));
|
||||
const logEles = parentEle.all(by.css('h4 ~ div'));
|
||||
const childViewInputEle = parentEle.element(by.css('app-child input'));
|
||||
let logCount = await logEles.count();
|
||||
|
||||
expect(childViewInputEle.getAttribute('value')).toContain('Magneta');
|
||||
expect(commentEle.isPresent()).toBe(false, 'comment should not be in DOM');
|
||||
|
||||
await sendKeys(childViewInputEle, '-test-');
|
||||
let count = await logEles.count();
|
||||
const count = await logEles.count();
|
||||
expect(childViewInputEle.getAttribute('value')).toContain('-test-');
|
||||
expect(commentEle.isPresent()).toBe(true, 'should have comment because >10 chars');
|
||||
expect(commentEle.getText()).toContain('long name');
|
||||
@ -132,11 +132,11 @@ describe('Lifecycle hooks', () => {
|
||||
});
|
||||
|
||||
it('should support spy\'s OnInit & OnDestroy hooks', async () => {
|
||||
let inputEle = element(by.css('spy-parent input'));
|
||||
let addHeroButtonEle = element(by.cssContainingText('spy-parent button', 'Add Hero'));
|
||||
let resetHeroesButtonEle = element(by.cssContainingText('spy-parent button', 'Reset Heroes'));
|
||||
let heroEles = element.all(by.css('spy-parent div[mySpy'));
|
||||
let logEles = element.all(by.css('spy-parent h4 ~ div'));
|
||||
const inputEle = element(by.css('spy-parent input'));
|
||||
const addHeroButtonEle = element(by.cssContainingText('spy-parent button', 'Add Hero'));
|
||||
const resetHeroesButtonEle = element(by.cssContainingText('spy-parent button', 'Reset Heroes'));
|
||||
const heroEles = element.all(by.css('spy-parent div[mySpy'));
|
||||
const logEles = element.all(by.css('spy-parent h4 ~ div'));
|
||||
|
||||
expect(heroEles.count()).toBe(2, 'should have two heroes displayed');
|
||||
expect(logEles.count()).toBe(2, 'should have two log entries');
|
||||
@ -153,10 +153,10 @@ describe('Lifecycle hooks', () => {
|
||||
});
|
||||
|
||||
it('should support "spy counter"', async () => {
|
||||
let updateCounterButtonEle = element(by.cssContainingText('counter-parent button', 'Update'));
|
||||
let resetCounterButtonEle = element(by.cssContainingText('counter-parent button', 'Reset'));
|
||||
let textEle = element(by.css('counter-parent app-counter > div'));
|
||||
let logEles = element.all(by.css('counter-parent h4 ~ div'));
|
||||
const updateCounterButtonEle = element(by.cssContainingText('counter-parent button', 'Update'));
|
||||
const resetCounterButtonEle = element(by.cssContainingText('counter-parent button', 'Reset'));
|
||||
const textEle = element(by.css('counter-parent app-counter > div'));
|
||||
const logEles = element.all(by.css('counter-parent h4 ~ div'));
|
||||
|
||||
expect(textEle.getText()).toContain('Counter = 0');
|
||||
expect(logEles.count()).toBe(2, 'should start with two log entries');
|
||||
|
@ -67,8 +67,8 @@ export class AfterContentComponent implements AfterContentChecked, AfterContentI
|
||||
}
|
||||
|
||||
private logIt(method: string) {
|
||||
let child = this.contentChild;
|
||||
let message = `${method}: ${child ? child.hero : 'no'} child content`;
|
||||
const child = this.contentChild;
|
||||
const message = `${method}: ${child ? child.hero : 'no'} child content`;
|
||||
this.logger.log(message);
|
||||
}
|
||||
// #docregion hooks
|
||||
|
@ -67,7 +67,7 @@ export class AfterViewComponent implements AfterViewChecked, AfterViewInit {
|
||||
// #docregion do-something
|
||||
// This surrogate for real business logic sets the `comment`
|
||||
private doSomething() {
|
||||
let c = this.viewChild.hero.length > 10 ? `That's a long name` : '';
|
||||
const c = this.viewChild.hero.length > 10 ? `That's a long name` : '';
|
||||
if (c !== this.comment) {
|
||||
// Wait a tick because the component's view has already been checked
|
||||
this.logger.tick_then(() => this.comment = c);
|
||||
@ -76,8 +76,8 @@ export class AfterViewComponent implements AfterViewChecked, AfterViewInit {
|
||||
// #enddocregion do-something
|
||||
|
||||
private logIt(method: string) {
|
||||
let child = this.viewChild;
|
||||
let message = `${method}: ${child ? child.hero : 'no'} child view`;
|
||||
const child = this.viewChild;
|
||||
const message = `${method}: ${child ? child.hero : 'no'} child view`;
|
||||
this.logger.log(message);
|
||||
}
|
||||
// #docregion hooks
|
||||
|
@ -31,9 +31,9 @@ export class MyCounterComponent implements OnChanges {
|
||||
}
|
||||
|
||||
// A change to `counter` is the only change we care about
|
||||
let chng = changes.counter;
|
||||
let cur = chng.currentValue;
|
||||
let prev = JSON.stringify(chng.previousValue); // first time is {}; after is integer
|
||||
const chng = changes.counter;
|
||||
const cur = chng.currentValue;
|
||||
const prev = JSON.stringify(chng.previousValue); // first time is {}; after is integer
|
||||
this.changeLog.push(`counter: currentValue = ${cur}, previousValue = ${prev}`);
|
||||
}
|
||||
}
|
||||
|
@ -51,8 +51,8 @@ export class DoCheckComponent implements DoCheck {
|
||||
this.noChangeCount = 0;
|
||||
} else {
|
||||
// log that hook was called when there was no relevant change.
|
||||
let count = this.noChangeCount += 1;
|
||||
let noChangeMsg = `DoCheck called ${count}x when no change to hero or power`;
|
||||
const count = this.noChangeCount += 1;
|
||||
const noChangeMsg = `DoCheck called ${count}x when no change to hero or power`;
|
||||
if (count === 1) {
|
||||
// add new "no change" message
|
||||
this.changeLog.push(noChangeMsg);
|
||||
|
@ -34,10 +34,10 @@ export class OnChangesComponent implements OnChanges {
|
||||
|
||||
// #docregion ng-on-changes
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
for (let propName in changes) {
|
||||
let chng = changes[propName];
|
||||
let cur = JSON.stringify(chng.currentValue);
|
||||
let prev = JSON.stringify(chng.previousValue);
|
||||
for (const propName in changes) {
|
||||
const chng = changes[propName];
|
||||
const cur = JSON.stringify(chng.currentValue);
|
||||
const prev = JSON.stringify(chng.previousValue);
|
||||
this.changeLog.push(`${propName}: currentValue = ${cur}, previousValue = ${prev}`);
|
||||
}
|
||||
}
|
||||
|
@ -48,16 +48,16 @@ export class PeekABooComponent extends PeekABooDirective implements
|
||||
constructor(logger: LoggerService) {
|
||||
super(logger);
|
||||
|
||||
let is = this.name ? 'is' : 'is not';
|
||||
const is = this.name ? 'is' : 'is not';
|
||||
this.logIt(`name ${is} known at construction`);
|
||||
}
|
||||
|
||||
// only called for/if there is an @input variable set by parent.
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
let changesMsgs: string[] = [];
|
||||
for (let propName in changes) {
|
||||
const changesMsgs: string[] = [];
|
||||
for (const propName in changes) {
|
||||
if (propName === 'name') {
|
||||
let name = changes.name.currentValue;
|
||||
const name = changes.name.currentValue;
|
||||
changesMsgs.push(`name ${this.verb} to "${name}"`);
|
||||
} else {
|
||||
changesMsgs.push(propName + ' ' + this.verb);
|
||||
|
Reference in New Issue
Block a user