Skip to content

Instantly share code, notes, and snippets.

View Oleg-Sulzhenko's full-sized avatar

Oleh Oleg-Sulzhenko

View GitHub Profile
By using the second argument of the Effect Hook with care, you can decide whether it runs:
every time (no argument)
only on mount and unmount ([] argument)
only when a certain variable changes (e.g. [count] argument)
End To End — Testing full blown user flows in the browser.
These tests consist of minimal mocks (i.e — you really are spinning up all the services that the user would be using).
Integration — Testing interactions between multiple services / components.
An “Integration test” is a bloated and often ambiguous term. For example, setting up a test that verifies interactions between multiple services (e.g — an api and a database) has overhead associated with it that is close to writing a full blown E2E test. On the other hand, writing a test that multiple react components work together in a redux environment has the complexity that is closer to a unit test. Read on to find out why ;)
Unit — Testing a single component / function in isolation.
A unit test is essentially testing input and output. It doesn’t get easier to reason about than this.
Some other types of testing:
Manual — A human being actually going through and verifying a flow on a real device.
Snapshot— Verifying a component’s rendered output.
Static — Te
import {connect} from "react-redux";
const mapStateToProps = state => {
return {
roles: state.user.user.roles,
roleConfigs: state.user.roleConfigs
}
};
const mapDispatchToProps = dispatch => {
Используйте switchMap когда вам нужно игнорировать предыдущее диспетчеризованное действие при поступлении нового действия.
Используйте mergeMap в том случае, если нужно параллельно обрабатывать все диспетчеризованные действия.
Используйте concatMap тогда, когда действия нужно обрабатывать одно за другим, в порядке их поступления.
Используйте exhaustMap в ситуациях, когда, в процессе обработки ранее поступивших действий, вам нужно игнорировать новые.
Иногда вам, для выполнения некоего действия, могут понадобиться данные из нескольких наблюдаемых объектов.
В подобной ситуации избегайте создания подписок на такие объекты внутри блоков subscribe других наблюдаемых объектов.
Вместо этого применяйте подходящие операторы для объединения команд в цепочки.
Среди таких операторов можно отметить withLatestFrom и combineLatest.
@Oleg-Sulzhenko
Oleg-Sulzhenko / dsafgh
Last active June 18, 2019 13:58
https://stackoverflow.com/questions/52845192/rxjs-stop-propagation-of-observable-chain-if-certain-condition-is-met/52845452 почему subscribe in subscribe это плохо ?? каким оператором отмкнеть предыдущий API call ??
this.service.getFileableSARs()
.mergeMap((res: any) => {
if (!(res.length === 0)) {
this.snackbar.error('There are no pending SAR Reports to file');
this.snackbar.info('Redirecting to overview...');
this.router.navigate([`/sars/batches`]);
} else {
return this.service.generateSARBatch();
}
})
@Oleg-Sulzhenko
Oleg-Sulzhenko / yo
Last active March 20, 2019 11:12
http://www.marcusoft.net/2015/08/pre-and-post-hooks-for-npm-scripting.html good article about how to run script after/before build/test/etc.
_
<ng-container *ngIf="{
users: users$ | async,
adminsList: adminsList$ | async
} as data">
<div class="ads-table__content">
<div *ngFor="let user of data.users" class="users__item">
<div>{{user.userName}}</div>
<div>{{user.email}}</div>
//This is test suite
describe("Test Suite", function() {
it("test spec", function() {
expect( expression ).toEqual(true);
});
});
-------------------------------------------------------------------------
Matchers
toBe() passed if the actual value is of the same type and value as that of the expected value. It compares with === operator
providers: [{
provide: HTTP_INTERCEPTORS,
useClass: ErrorInterceptor,
multi: true,
}]
@Oleg-Sulzhenko
Oleg-Sulzhenko / jasmine-ref
Last active February 27, 2019 17:20
ngDocs => https://angular.io/guide/testing https://stackoverflow.com/questions/22093418/jasmine-unit-test-skipped-by-my-karma-configuration How to run specific test only - When using **iit** or **ddescribe**, you set focus only on this test/suite.
const bannerDe: DebugElement = fixture.debugElement;
const bannerEl: HTMLElement = bannerDe.nativeElement;
*ngDocs
Angular relies on the DebugElement abstraction to work safely across all supported platforms. Instead of creating an HTML element tree,
Angular creates a DebugElement tree that wraps the native elements for the runtime platform.
The nativeElement property unwraps the DebugElement and returns the platform-specific element object.
** The DebugElement has other methods and properties that are useful in tests, as you'll see elsewhere in this guide.
https://angular.io/guide/testing#bycss