Slide 77
Slide 77 text
IMPLEMENT YOUR COMPONENT TEST HARNESS
import { SentimentRatingHarnessFilters } from './sentiment-rating-harness-filters';
import { AsyncFactoryFn, ComponentHarness, HarnessPredicate, parallel, TestElement } from '@angular/cdk/testing';
1
2
3
export class SentimentRatingHarness extends ComponentHarness {
4
static hostSelector = 'app-sentiment-rating';
5
6
static with(options: SentimentRatingHarnessFilters): HarnessPredicate {
7
return new HarnessPredicate(SentimentRatingHarness, options)
8
.addOption('rate', options.rate,
9
async (harness, rate) => await harness.getRate() === rate
10
);
11
}
12
13
private _rateButtons: AsyncFactoryFn = this.locatorForAll('button');
14
15
public async getRate(): Promise {
16
const btns = await this._rateButtons();
17
return (await parallel(() => btns.map(b => b.text()))).reduce((acc, curr) => curr === 'favorite' ? ++acc: acc, 0);
18
}
19
20
public async setRate(rate: number): Promise {
21
if (rate <= 0) throw Error('Rate is invalid');
22
23
const btns = await this._rateButtons();
24
static with(options: SentimentRatingHarnessFilters): HarnessPredicate {
}
import { AsyncFactoryFn, ComponentHarness, HarnessPredicate, parallel, TestElement } from '@angular/cdk/testing';
1
import { SentimentRatingHarnessFilters } from './sentiment-rating-harness-filters';
2
3
export class SentimentRatingHarness extends ComponentHarness {
4
static hostSelector = 'app-sentiment-rating';
5
6
7
return new HarnessPredicate(SentimentRatingHarness, options)
8
.addOption('rate', options.rate,
9
async (harness, rate) => await harness.getRate() === rate
10
);
11
12
13
private _rateButtons: AsyncFactoryFn = this.locatorForAll('button');
14
15
public async getRate(): Promise {
16
const btns = await this._rateButtons();
17
return (await parallel(() => btns.map(b => b.text()))).reduce((acc, curr) => curr === 'favorite' ? ++acc: acc, 0);
18
}
19
20
public async setRate(rate: number): Promise {
21
if (rate <= 0) throw Error('Rate is invalid');
22
23
const btns = await this._rateButtons();
24
return new HarnessPredicate(SentimentRatingHarness, options)
.addOption('rate', options.rate,
);
import { AsyncFactoryFn, ComponentHarness, HarnessPredicate, parallel, TestElement } from '@angular/cdk/testing';
1
import { SentimentRatingHarnessFilters } from './sentiment-rating-harness-filters';
2
3
export class SentimentRatingHarness extends ComponentHarness {
4
static hostSelector = 'app-sentiment-rating';
5
6
static with(options: SentimentRatingHarnessFilters): HarnessPredicate {
7
8
9
async (harness, rate) => await harness.getRate() === rate
10
11
}
12
13
private _rateButtons: AsyncFactoryFn = this.locatorForAll('button');
14
15
public async getRate(): Promise {
16
const btns = await this._rateButtons();
17
return (await parallel(() => btns.map(b => b.text()))).reduce((acc, curr) => curr === 'favorite' ? ++acc: acc, 0);
18
}
19
20
public async setRate(rate: number): Promise {
21
if (rate <= 0) throw Error('Rate is invalid');
22
23
const btns = await this._rateButtons();
24
async (harness, rate) => await harness.getRate() === rate
import { AsyncFactoryFn, ComponentHarness, HarnessPredicate, parallel, TestElement } from '@angular/cdk/testing';
1
import { SentimentRatingHarnessFilters } from './sentiment-rating-harness-filters';
2
3
export class SentimentRatingHarness extends ComponentHarness {
4
static hostSelector = 'app-sentiment-rating';
5
6
static with(options: SentimentRatingHarnessFilters): HarnessPredicate {
7
return new HarnessPredicate(SentimentRatingHarness, options)
8
.addOption('rate', options.rate,
9
10
);
11
}
12
13
private _rateButtons: AsyncFactoryFn = this.locatorForAll('button');
14
15
public async getRate(): Promise {
16
const btns = await this._rateButtons();
17
return (await parallel(() => btns.map(b => b.text()))).reduce((acc, curr) => curr === 'favorite' ? ++acc: acc, 0);
18
}
19
20
public async setRate(rate: number): Promise {
21
if (rate <= 0) throw Error('Rate is invalid');
22
23
const btns = await this._rateButtons();
24
import { AsyncFactoryFn, ComponentHarness, HarnessPredicate, parallel, TestElement } from '@angular/cdk/testing';
import { SentimentRatingHarnessFilters } from './sentiment-rating-harness-filters';
export class SentimentRatingHarness extends ComponentHarness {
static hostSelector = 'app-sentiment-rating';
static with(options: SentimentRatingHarnessFilters): HarnessPredicate {
return new HarnessPredicate(SentimentRatingHarness, options)
.addOption('rate', options.rate,
async (harness, rate) => await harness.getRate() === rate
);
}
private _rateButtons: AsyncFactoryFn = this.locatorForAll('button');
public async getRate(): Promise {
const btns = await this._rateButtons();
return (await parallel(() => btns.map(b => b.text()))).reduce((acc, curr) => curr === 'favorite' ? ++acc: acc, 0);
}
public async setRate(rate: number): Promise {
if (rate <= 0) throw Error('Rate is invalid');
const btns = await this._rateButtons();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24