Skip to content

Commit

Permalink
feat(settings): add recommended strict settings to compiler options
Browse files Browse the repository at this point in the history
- update typescript configuration
- eliminate strict checking violations
- update unit tests where changes were made

closes #536
  • Loading branch information
slegge committed Mar 25, 2021
1 parent c72a6c6 commit 6480960
Show file tree
Hide file tree
Showing 22 changed files with 55 additions and 36 deletions.
8 changes: 7 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1536kb"
},
{
"type": "bundle",
"name": "polyfills",
Expand All @@ -73,7 +78,8 @@
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb"
"maximumWarning": "2kb",
"maximumError": "4kb"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('AuthEffects', () => {
const effect = new AuthEffects(actions, localStorageService, router);
const metadata = getEffectsMetadata(effect);

expect(metadata.login.dispatch).toEqual(false);
expect(metadata.login?.dispatch).toEqual(false);
});

it('should call setItem on LocalStorageService', () => {
Expand All @@ -55,7 +55,7 @@ describe('AuthEffects', () => {
const effect = new AuthEffects(actions, localStorageService, router);
const metadata = getEffectsMetadata(effect);

expect(metadata.logout.dispatch).toEqual(false);
expect(metadata.logout?.dispatch).toEqual(false);
});

it('should call setItem on LocalStorageService and navigate to about', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('GoogleAnalyticsEffects', () => {
const effect = new GoogleAnalyticsEffects(router);
const metadata = getEffectsMetadata(effect);

expect(metadata.pageView.dispatch).toEqual(false);
expect(metadata.pageView?.dispatch).toEqual(false);
});

it('should call google analytics', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('LocalStorageService', () => {
service.setItem('TEST', 'item');
expect(service.getItem('TEST')).toBe('item');
service.removeItem('TEST');
expect(service.getItem('TEST')).toBe(null);
expect(service.getItem('TEST')).toEqual({});
});

it('should load initial state', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('BooksEffects', () => {
const effects = new BooksEffects(actions, store, localStorage);
const metadata = getEffectsMetadata(effects);

expect(metadata.persistBooks.dispatch).toEqual(false);
expect(metadata.persistBooks?.dispatch).toEqual(false);
});

it('should call setItem on LocalStorageService for delete one action', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('BookReducer', () => {
const state = bookReducer(TEST_INITIAL_STATE, action);

expect(state.ids.length).toEqual(2);
expect(state.entities['1234'].title).toEqual('test');
expect(state.entities['1234']?.title).toEqual('test');
});

it('should update a book', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('CrudComponent', () => {
}).compileComponents();
store = TestBed.inject(MockStore);
store.overrideSelector(selectAllBooks, []);
store.overrideSelector(selectSelectedBook, null);
store.overrideSelector(selectSelectedBook, undefined);
fixture = TestBed.createComponent(CrudComponent);
component = fixture.componentInstance;
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('SettingsEffects', () => {
titleService
);
const metadata = getEffectsMetadata(effect);
expect(metadata.setTranslateServiceLanguage.dispatch).toEqual(false);
expect(metadata.setTranslateServiceLanguage?.dispatch).toEqual(false);
});
});

Expand All @@ -66,7 +66,7 @@ describe('SettingsEffects', () => {
);
const metadata = getEffectsMetadata(effect);

expect(metadata.setTitle.dispatch).toEqual(false);
expect(metadata.setTitle?.dispatch).toEqual(false);
});

it('should setTitle', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('FormEffects', () => {
const effect = new FormEffects(actions, localStorageService);
const metadata = getEffectsMetadata(effect);

expect(metadata.persistForm.dispatch).toEqual(false);
expect(metadata.persistForm?.dispatch).toEqual(false);
});

it('should call setItem on LocalStorageService for UPDATE action', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { User, UserService } from '../user.service';
})
export class UserComponent implements OnInit {
routeAnimationsElements = ROUTE_ANIMATIONS_ELEMENTS;
userForm: FormGroup | undefined;
userForm: FormGroup = new FormGroup({});
users$: Observable<User[]> | undefined;
isEdit$: Observable<{ value: boolean }> | undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h1 rtl class="main-heading">{{ 'anms.examples.stocks.title' | translate }}</h1>
<mat-form-field>
<input matInput [placeholder]="'anms.examples.stocks.symbol' | translate"
[value]="stocks.symbol"
(keyup)="onSymbolChange($event.target.value)">
(keyup)="onSymbolChange($event)">
</mat-form-field>
</form>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ export class StockMarketContainerComponent implements OnInit {
this.stocks$ = this.store.pipe(select(selectStockMarket));
this.stocks$
.pipe(take(1))
.subscribe((stocks) => this.onSymbolChange(stocks.symbol));
.subscribe((stocks) => this.onSymbolValue(stocks.symbol));
}

onSymbolChange(symbol: string) {
onSymbolValue(symbol: string) {
this.store.dispatch(actionStockMarketRetrieve({ symbol }));
}

onSymbolChange(event: any) {
this.onSymbolValue(event.target.value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import {
import { StockMarketEffects, STOCK_MARKET_KEY } from './stock-market.effects';
import { Stock } from './stock-market.model';
import { StockMarketService } from './stock-market.service';
import { RunHelpers } from 'rxjs/internal/testing/TestScheduler';

const symbol = 'TSLA';

describe('StockMarketEffects', () => {
let localStorage: jasmine.SpyObj<LocalStorageService>;
let stockMarket: jasmine.SpyObj<StockMarketService>;
let scheduler;
let scheduler: TestScheduler;

beforeEach(() => {
localStorage = jasmine.createSpyObj('localStorageService', ['setItem']);
Expand All @@ -30,7 +31,7 @@ describe('StockMarketEffects', () => {
});

it('should emit ActionStockMarketRetrieveSuccess on success', (done) => {
scheduler.run((helpers) => {
scheduler.run((helpers: RunHelpers) => {
const { cold, expectObservable } = helpers;
const retrieveAction1 = actionStockMarketRetrieve({
symbol
Expand Down Expand Up @@ -88,7 +89,7 @@ describe('StockMarketEffects', () => {
});

it('should emit ActionStockMarketRetrieveError on error', () => {
scheduler.run((helpers) => {
scheduler.run((helpers: RunHelpers) => {
const { cold, expectObservable } = helpers;
const retrieveAction = actionStockMarketRetrieve({
symbol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ describe('StockMarketReducer', () => {
const state = stockMarketReducer(originalState, action);

expect(state.loading).toBeTruthy();
expect(state.stock).toBeNull();
expect(state.error).toBeNull();
expect(state.stock).toBeUndefined();
expect(state.error).toBeUndefined();
expect(state.symbol).toBe(action.symbol);
});
});
Expand All @@ -63,7 +63,7 @@ describe('StockMarketReducer', () => {

expect(state.symbol).toBe(state.symbol);
expect(state.loading).toBeFalsy();
expect(state.stock).toBeNull();
expect(state.stock).toBeUndefined();
expect(state.error).toBe(error);
});
});
Expand All @@ -85,7 +85,7 @@ describe('StockMarketReducer', () => {

expect(state.loading).toBeFalsy();
expect(state.stock).toBe(stock);
expect(state.error).toBeNull();
expect(state.error).toBeUndefined();
expect(state.symbol).toBe(state.symbol);
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<div class="container">
<div class="row">
<div class="offset-md-2 col-md-8 entry">
<anms-big-input rtl [placeholder]="'anms.examples.todos.input' | translate" [value]="newTodo" (keyup)="onNewTodoChange($event.target.value)"
<anms-big-input rtl [placeholder]="'anms.examples.todos.input' | translate" [value]="newTodo" (keyup)="onNewTodoChange($event)"
(keyup.enter)="!isAddTodoDisabled && onAddTodo()" (keyup.escape)="onNewTodoClear()">
<anms-big-input-action fontSet="fas" fontIcon="fa-plus" faIcon="plus" color="accent"
<anms-big-input-action fontSet="fas" fontIcon="plus" faIcon="plus" color="accent"
(action)="onAddTodo()" [disabled]="isAddTodoDisabled" [matTooltip]="'anms.examples.todos.tooltip.add' | translate"
matTooltipPosition="before">
</anms-big-input-action>
<anms-big-input-action fontSet="fas" fontIcon="fa-trash" faIcon="trash" color="warn"
(action)="onRemoveDoneTodos()" [disabled]="removeDoneDisabled$ | async"
<anms-big-input-action fontSet="fas" fontIcon="trash" faIcon="trash" color="warn"
(action)="onRemoveDoneTodos()" [disabled]="(removeDoneDisabled$ | async) || false"
[matTooltip]="'anms.examples.todos.tooltip.remove' | translate" matTooltipPosition="after">
</anms-big-input-action>
</anms-big-input>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TranslateService } from '@ngx-translate/core';
import { MatSnackBar } from '@angular/material/snack-bar';
import { select, Store } from '@ngrx/store';
import { take } from 'rxjs/operators';
import { Observable } from 'rxjs';
import { Observable, of as observableOf } from 'rxjs';

import {
ROUTE_ANIMATIONS_ELEMENTS,
Expand All @@ -26,7 +26,7 @@ export class TodosContainerComponent implements OnInit {
routeAnimationsElements = ROUTE_ANIMATIONS_ELEMENTS;
todos$: Observable<Todo[]> | undefined;
filter$: Observable<TodosFilter> | undefined;
removeDoneDisabled$: Observable<boolean> | undefined;
removeDoneDisabled$: Observable<boolean> = observableOf(false);
newTodo = '';

constructor(
Expand All @@ -48,8 +48,8 @@ export class TodosContainerComponent implements OnInit {
return this.newTodo.length < 4;
}

onNewTodoChange(newTodo: string) {
this.newTodo = newTodo;
onNewTodoChange(event: any) {
this.newTodo = event.target.value;
}

onNewTodoClear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('TodosEffects', () => {
const effect = new TodosEffects(actions$, store, localStorage);
const metadata = getEffectsMetadata(effect);

expect(metadata.persistTodos.dispatch).toEqual(false);
expect(metadata.persistTodos?.dispatch).toEqual(false);
});

it('should call setItem on LocalStorageService for any action', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ describe('BigInputActionComponent', () => {

it('should display icon if fontSet and fontIcon properties are set', () => {
const template =
'<anms-big-input-action fontSet="fas" fontIcon="fa-trash"></anms-big-input-action>';
'<anms-big-input-action fontSet="fas" fontIcon="trash"></anms-big-input-action>';
fixture = createHostComponent(template);
expect(getIcon()).toBeTruthy();
expect(getIcon().nativeElement.classList.contains('fa-trash')).toBeTruthy();
expect(getIcon().nativeElement.classList.contains('trash')).toBeTruthy();
expect(getIcon().nativeElement.classList.contains('fas')).toBeTruthy();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
ChangeDetectionStrategy
} from '@angular/core';

import { IconProp } from '@fortawesome/fontawesome-svg-core';

@Component({
selector: 'anms-big-input-action',
templateUrl: './big-input-action.component.html',
Expand All @@ -20,7 +22,7 @@ export class BigInputActionComponent {
@Input()
fontIcon = '';
@Input()
faIcon = '';
faIcon: IconProp | undefined;
@Input()
label = '';
@Input()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { SharedModule } from '../../shared.module';
`
})
class HostComponent {
newValue: string;
newValue = '';
onKeyEvent(eventData: any) {}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('RtlSupportDirective', () => {
let fixture: ComponentFixture<TestComponent>;
let des: DebugElement[]; // the three elements w/ the directive
let bareH2: DebugElement; // the <h2> w/o the directive
let languageSubject;
let languageSubject: BehaviorSubject<{ lang: string }>;

beforeEach(() => {
languageSubject = new BehaviorSubject({ lang: 'he' });
Expand Down
6 changes: 6 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"strict": true,
"strictNullChecks": true,
"noImplicitAny": true,
"strictPropertyInitialization": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"target": "es2015",
"typeRoots": ["node_modules/@types"],
"lib": ["es2018", "dom"]
},
"angularCompilerOptions": {
"strictTemplates": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
Expand Down

0 comments on commit 6480960

Please sign in to comment.