SlideShare a Scribd company logo
1 of 27
Download to read offline
TESTING RXJS USING MARBLES
within Angular
( Lightning talk )
BOUT ME
{
"name": "Ilia Idakiev",
"experience": [
"Developer / Founder @ HNS",
"Lecturer in 'Advanced JS' @ FMI",
"Contractor / Consultant",
"2 Angular Courses @ HB (2016 - 2017)",
"JavaScript Courses"
],
"involvedIn": [
"SofiaJS", "BeerJS", "Angular Sofia"
]
}
UNITTESTING
In computer programming, unit testing is a software testing method by
which individual units of source code, sets of one or more computer
program modules together with associated control data, usage
procedures, and operating procedures, are tested to determine whether
they are fit for use.
(wikipedia)
TESTING ANGULAR
• Jasmine - test framework that provides everything needed to write
basic tests.
• Karma - test runner for writing and running unit tests while
developing the application.
JASMINE SUITS - DESCRIBE
A test suite begins with a call to the global Jasmine function describe
with two parameters: a string and a function.The string is a name or
title for a spec suite - usually what is being tested.The function is a
block of code that implements the suite.
JASMINE SPECS - IT
Specs are defined by calling the global Jasmine function it, which, like
describe takes a string and a function.The string is the title of the spec
and the function is the spec, or test.
A spec contains one or more expectations that test the state of the
code.An expectation in Jasmine is an assertion that is either true or
false.A spec with all true expectations is a passing spec.A spec with
one or more false expectations is a failing spec.
JASMINE EXPECTATIONS - EXPECT
Expectations are built with the function expect which takes a value,
called the actual. It is chained with a Matcher function, which takes the
expected value.
JASMINETEST EXAMPLE
RXJS
RxJS is a library for reactive programming using Observables, to make it
easier to compose asynchronous or callback-based code.
https://github.com/ReactiveX/rxjs
HOTVS COLD OBSERVABLES
• Cold observables start running upon individual subscriptions and
values are not shared among subscribers.
• The hot observable sequence is shared among all subscribers.When
an observer subscribes to a hot observable sequence, it will get all
values in the stream that are emitted after it subscribes.
COLD
OBSERVABLE
EXAMPLE
HOT
OBSERVABLE
EXAMPLE
ANALOGIES
• Cold Observables - movies
• Hot Observables - live performances.
• Hot Observables replayed - live performances recorded on video.
( BehaviorSubject / ReplaySubject )
MARBLE DIAGRAMS
Marble diagrams are frequently used to explaining how certain
operators in Rx work.
MARBLE EXAMPLE
MORE MARBLE DIAGRAMS
http://rxmarbles.com
JASMINE-MARBLES
Library that provides marble testing helpers for RxJS and Jasmine
Marble tests use a specialized VirtualScheduler called the TestScheduler.
They enable us to test asynchronous operations in a synchronous and
dependable manner.
MARBLE SYNTAX
• "-" time: 10 "frames" of time passage.
• "|" complete: The successful completion of an observable.This is the observable producer signaling
complete()
• "#" error: An error terminating the observable.This is the observable producer signaling error()
• "a" any character: All other characters represent a value being emitted by the producure signaling next()
• "()" sync groupings: When multiple events need to single in the same frame synchronously, parenthesis are
used to group those events.You can group nexted values, a completion or an error in this manner.The
position of the initial ( determines the time at which its values are emitted.
• "^" subscription point: (hot observables only) shows the point at which the tested observables will be
subscribed to the hot observable.This is the "zero frame" for that observable, every frame before the ^ will
be negative.
BASIC METHODS
• hot(marbles: string, values?: object, error?: any) - creates a "hot" observable (a subject) that will behave as
though it's already "running" when the test begins.An interesting difference is that hot marbles allow a ^ character to
signal where the "zero frame" is.That is the point at which the subscription to observables being tested begins.
• cold(marbles: string, values?: object, error?: any) - creates a "cold" observable whose subscription starts when
the test begins.
• expectObservable(actual: Observable<T>)

.toBe(marbles: string, values?: object, error?: any) - schedules an assertion for when theTestScheduler
flushes.TheTestScheduler will automatically flush at the end of your jasmine it block.
• expectSubscriptions(actualSubscriptionLogs: SubscriptionLog[])

.toBe(subscriptionMarbles: string) - like expectObservable schedules an assertion for when the testScheduler
flushes. Both cold() and hot() return an observable with a property subscriptions of type SubscriptionLog[]. Give
subscriptions as parameter to expectSubscriptions to assert whether it matches the subscriptionsMarbles marble
diagram given in toBe(). Subscription marble diagrams are slightly different than Observable marble diagrams.
MARBLE EXAMPLES
• '-' or '------': Equivalent to Observable.never(), or an observable that never emits or completes
• '|': Equivalent to Observable.empty()
• '#': Equivalent to Observable.throw()
• '--a--':An observable that waits 20 "frames", emits value a and then never completes.
• '--a--b--|': On frame 20 emit a, on frame 50 emit b, and on frame 80, complete
• '--a--b--#': On frame 20 emit a, on frame 50 emit b, and on frame 80, error
• '-a-^-b--|': In a hot observable, on frame -20 emit a, then on frame 20 emit b, and on frame 50, complete.
• '--(abc)-|': on frame 20, emit a, b, and c, then on frame 40 complete
• '-----(a|)': on frame 50, emit a and complete.
EXAMPLE 1
EXAMPLE 2
SUBSCRIPTION MARBLE SYNTAX
• "-" time: 10 "frames" of the passage.
• "^" subscription point: shows the point in time at which a
subscription happen.
• "!" unsubscription point: shows the point in time at which a
subscription is unsubscribed.
EXAMPLE 3
ANGULAR DEMO
CONTACT
• GitHub - https://github/iliaidakiev (/slides/ - list of future and past events)
• Twitter - @ilia_idakiev
THANKYOU!

More Related Content

What's hot

Qtp training session IV
Qtp training session IVQtp training session IV
Qtp training session IV
Aisha Mazhar
 

What's hot (20)

Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013
 
Reactive programming in Angular 2
Reactive programming in Angular 2Reactive programming in Angular 2
Reactive programming in Angular 2
 
Introduction to akka actors with java 8
Introduction to akka actors with java 8Introduction to akka actors with java 8
Introduction to akka actors with java 8
 
VJUG24 - Reactive Integrations with Akka Streams
VJUG24  - Reactive Integrations with Akka StreamsVJUG24  - Reactive Integrations with Akka Streams
VJUG24 - Reactive Integrations with Akka Streams
 
RxJava - introduction & design
RxJava - introduction & designRxJava - introduction & design
RxJava - introduction & design
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
 
Unit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJSUnit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJS
 
Testing akka-actors
Testing akka-actorsTesting akka-actors
Testing akka-actors
 
Building an aws sdk for Perl - Granada Perl Workshop 2014
Building an aws sdk for Perl - Granada Perl Workshop 2014Building an aws sdk for Perl - Granada Perl Workshop 2014
Building an aws sdk for Perl - Granada Perl Workshop 2014
 
Advance JS and oop
Advance JS and oopAdvance JS and oop
Advance JS and oop
 
Welcome Azure Functions 2. 0
Welcome Azure Functions 2. 0Welcome Azure Functions 2. 0
Welcome Azure Functions 2. 0
 
Paws: A Perl AWS SDK - YAPC Europe 2015
Paws: A Perl AWS SDK - YAPC Europe 2015Paws: A Perl AWS SDK - YAPC Europe 2015
Paws: A Perl AWS SDK - YAPC Europe 2015
 
Unit testing in JavaScript with Jasmine and Karma
Unit testing in JavaScript with Jasmine and KarmaUnit testing in JavaScript with Jasmine and Karma
Unit testing in JavaScript with Jasmine and Karma
 
Building a chatbot – step by step
Building a chatbot – step by stepBuilding a chatbot – step by step
Building a chatbot – step by step
 
Serverless cat detector workshop - cloudyna 2017 (16.12.2017)
Serverless cat detector   workshop - cloudyna 2017 (16.12.2017)Serverless cat detector   workshop - cloudyna 2017 (16.12.2017)
Serverless cat detector workshop - cloudyna 2017 (16.12.2017)
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
 
Programing for problem solving ( airline reservation system)
Programing for problem solving ( airline reservation system)Programing for problem solving ( airline reservation system)
Programing for problem solving ( airline reservation system)
 
Intro to front-end testing
Intro to front-end testingIntro to front-end testing
Intro to front-end testing
 
Qtp training session IV
Qtp training session IVQtp training session IV
Qtp training session IV
 
Introduction to underscore.js
Introduction to underscore.jsIntroduction to underscore.js
Introduction to underscore.js
 

Similar to Testing rx js using marbles within angular

Deploying MLlib for Scoring in Structured Streaming with Joseph Bradley
Deploying MLlib for Scoring in Structured Streaming with Joseph BradleyDeploying MLlib for Scoring in Structured Streaming with Joseph Bradley
Deploying MLlib for Scoring in Structured Streaming with Joseph Bradley
Databricks
 
Memory Management with Java and C++
Memory Management with Java and C++Memory Management with Java and C++
Memory Management with Java and C++
Mohammad Shaker
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
Todor Kolev
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
Todor Kolev
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
Todor Kolev
 
Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011
Agora Group
 

Similar to Testing rx js using marbles within angular (20)

Spock
SpockSpock
Spock
 
JavaScript Robotics
JavaScript RoboticsJavaScript Robotics
JavaScript Robotics
 
Deploying MLlib for Scoring in Structured Streaming with Joseph Bradley
Deploying MLlib for Scoring in Structured Streaming with Joseph BradleyDeploying MLlib for Scoring in Structured Streaming with Joseph Bradley
Deploying MLlib for Scoring in Structured Streaming with Joseph Bradley
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Testing in Scala. Adform Research
Testing in Scala. Adform ResearchTesting in Scala. Adform Research
Testing in Scala. Adform Research
 
Testing in Scala by Adform research
Testing in Scala by Adform researchTesting in Scala by Adform research
Testing in Scala by Adform research
 
Just Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration TestingJust Do It! ColdBox Integration Testing
Just Do It! ColdBox Integration Testing
 
RxJS In-Depth - AngularConnect 2015
RxJS In-Depth - AngularConnect 2015RxJS In-Depth - AngularConnect 2015
RxJS In-Depth - AngularConnect 2015
 
Drilling the Async Library
Drilling the Async LibraryDrilling the Async Library
Drilling the Async Library
 
Ruby Blocks
Ruby BlocksRuby Blocks
Ruby Blocks
 
Memory Management with Java and C++
Memory Management with Java and C++Memory Management with Java and C++
Memory Management with Java and C++
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
pull requests I sent to scala/scala (ny-scala 2019)
pull requests I sent to scala/scala (ny-scala 2019)pull requests I sent to scala/scala (ny-scala 2019)
pull requests I sent to scala/scala (ny-scala 2019)
 
Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011
 
Scala active record
Scala active recordScala active record
Scala active record
 
Alberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.jsAlberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.js
 
Scala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJSScala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJS
 
Rechecking TortoiseSVN with the PVS-Studio Code Analyzer
Rechecking TortoiseSVN with the PVS-Studio Code AnalyzerRechecking TortoiseSVN with the PVS-Studio Code Analyzer
Rechecking TortoiseSVN with the PVS-Studio Code Analyzer
 

More from Ilia Idakiev

More from Ilia Idakiev (19)

No more promises lets RxJS 2 Edit
No more promises lets RxJS 2 EditNo more promises lets RxJS 2 Edit
No more promises lets RxJS 2 Edit
 
Enterprise State Management with NGRX/platform
Enterprise State Management with NGRX/platformEnterprise State Management with NGRX/platform
Enterprise State Management with NGRX/platform
 
Deep Dive into Zone.JS
Deep Dive into Zone.JSDeep Dive into Zone.JS
Deep Dive into Zone.JS
 
RxJS Schedulers - Controlling Time
RxJS Schedulers - Controlling TimeRxJS Schedulers - Controlling Time
RxJS Schedulers - Controlling Time
 
Creating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-htmlCreating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-html
 
No More Promises! Let's RxJS!
No More Promises! Let's RxJS!No More Promises! Let's RxJS!
No More Promises! Let's RxJS!
 
Marble Testing RxJS streams
Marble Testing RxJS streamsMarble Testing RxJS streams
Marble Testing RxJS streams
 
Deterministic JavaScript Applications
Deterministic JavaScript ApplicationsDeterministic JavaScript Applications
Deterministic JavaScript Applications
 
Web Components Everywhere
Web Components EverywhereWeb Components Everywhere
Web Components Everywhere
 
Building Reusable Custom Elements With Angular
Building Reusable Custom Elements With AngularBuilding Reusable Custom Elements With Angular
Building Reusable Custom Elements With Angular
 
State management for enterprise angular applications
State management for enterprise angular applicationsState management for enterprise angular applications
State management for enterprise angular applications
 
Offline progressive web apps with NodeJS and React
Offline progressive web apps with NodeJS and ReactOffline progressive web apps with NodeJS and React
Offline progressive web apps with NodeJS and React
 
Predictable reactive state management for enterprise apps using NGRX/platform
Predictable reactive state management for enterprise apps using NGRX/platformPredictable reactive state management for enterprise apps using NGRX/platform
Predictable reactive state management for enterprise apps using NGRX/platform
 
Angular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of SpeedAngular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of Speed
 
Angular Offline Progressive Web Apps With NodeJS
Angular Offline Progressive Web Apps With NodeJSAngular Offline Progressive Web Apps With NodeJS
Angular Offline Progressive Web Apps With NodeJS
 
Introduction to Offline Progressive Web Applications
Introduction to Offline Progressive Web ApplicationsIntroduction to Offline Progressive Web Applications
Introduction to Offline Progressive Web Applications
 
Reflective injection using TypeScript
Reflective injection using TypeScriptReflective injection using TypeScript
Reflective injection using TypeScript
 
Zone.js
Zone.jsZone.js
Zone.js
 
Predictable reactive state management - ngrx
Predictable reactive state management - ngrxPredictable reactive state management - ngrx
Predictable reactive state management - ngrx
 

Recently uploaded

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 

Recently uploaded (20)

Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 

Testing rx js using marbles within angular

  • 1. TESTING RXJS USING MARBLES within Angular ( Lightning talk )
  • 2. BOUT ME { "name": "Ilia Idakiev", "experience": [ "Developer / Founder @ HNS", "Lecturer in 'Advanced JS' @ FMI", "Contractor / Consultant", "2 Angular Courses @ HB (2016 - 2017)", "JavaScript Courses" ], "involvedIn": [ "SofiaJS", "BeerJS", "Angular Sofia" ] }
  • 3. UNITTESTING In computer programming, unit testing is a software testing method by which individual units of source code, sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures, are tested to determine whether they are fit for use. (wikipedia)
  • 4. TESTING ANGULAR • Jasmine - test framework that provides everything needed to write basic tests. • Karma - test runner for writing and running unit tests while developing the application.
  • 5. JASMINE SUITS - DESCRIBE A test suite begins with a call to the global Jasmine function describe with two parameters: a string and a function.The string is a name or title for a spec suite - usually what is being tested.The function is a block of code that implements the suite.
  • 6. JASMINE SPECS - IT Specs are defined by calling the global Jasmine function it, which, like describe takes a string and a function.The string is the title of the spec and the function is the spec, or test. A spec contains one or more expectations that test the state of the code.An expectation in Jasmine is an assertion that is either true or false.A spec with all true expectations is a passing spec.A spec with one or more false expectations is a failing spec.
  • 7. JASMINE EXPECTATIONS - EXPECT Expectations are built with the function expect which takes a value, called the actual. It is chained with a Matcher function, which takes the expected value.
  • 9. RXJS RxJS is a library for reactive programming using Observables, to make it easier to compose asynchronous or callback-based code. https://github.com/ReactiveX/rxjs
  • 10. HOTVS COLD OBSERVABLES • Cold observables start running upon individual subscriptions and values are not shared among subscribers. • The hot observable sequence is shared among all subscribers.When an observer subscribes to a hot observable sequence, it will get all values in the stream that are emitted after it subscribes.
  • 13. ANALOGIES • Cold Observables - movies • Hot Observables - live performances. • Hot Observables replayed - live performances recorded on video. ( BehaviorSubject / ReplaySubject )
  • 14. MARBLE DIAGRAMS Marble diagrams are frequently used to explaining how certain operators in Rx work.
  • 17. JASMINE-MARBLES Library that provides marble testing helpers for RxJS and Jasmine Marble tests use a specialized VirtualScheduler called the TestScheduler. They enable us to test asynchronous operations in a synchronous and dependable manner.
  • 18. MARBLE SYNTAX • "-" time: 10 "frames" of time passage. • "|" complete: The successful completion of an observable.This is the observable producer signaling complete() • "#" error: An error terminating the observable.This is the observable producer signaling error() • "a" any character: All other characters represent a value being emitted by the producure signaling next() • "()" sync groupings: When multiple events need to single in the same frame synchronously, parenthesis are used to group those events.You can group nexted values, a completion or an error in this manner.The position of the initial ( determines the time at which its values are emitted. • "^" subscription point: (hot observables only) shows the point at which the tested observables will be subscribed to the hot observable.This is the "zero frame" for that observable, every frame before the ^ will be negative.
  • 19. BASIC METHODS • hot(marbles: string, values?: object, error?: any) - creates a "hot" observable (a subject) that will behave as though it's already "running" when the test begins.An interesting difference is that hot marbles allow a ^ character to signal where the "zero frame" is.That is the point at which the subscription to observables being tested begins. • cold(marbles: string, values?: object, error?: any) - creates a "cold" observable whose subscription starts when the test begins. • expectObservable(actual: Observable<T>)
 .toBe(marbles: string, values?: object, error?: any) - schedules an assertion for when theTestScheduler flushes.TheTestScheduler will automatically flush at the end of your jasmine it block. • expectSubscriptions(actualSubscriptionLogs: SubscriptionLog[])
 .toBe(subscriptionMarbles: string) - like expectObservable schedules an assertion for when the testScheduler flushes. Both cold() and hot() return an observable with a property subscriptions of type SubscriptionLog[]. Give subscriptions as parameter to expectSubscriptions to assert whether it matches the subscriptionsMarbles marble diagram given in toBe(). Subscription marble diagrams are slightly different than Observable marble diagrams.
  • 20. MARBLE EXAMPLES • '-' or '------': Equivalent to Observable.never(), or an observable that never emits or completes • '|': Equivalent to Observable.empty() • '#': Equivalent to Observable.throw() • '--a--':An observable that waits 20 "frames", emits value a and then never completes. • '--a--b--|': On frame 20 emit a, on frame 50 emit b, and on frame 80, complete • '--a--b--#': On frame 20 emit a, on frame 50 emit b, and on frame 80, error • '-a-^-b--|': In a hot observable, on frame -20 emit a, then on frame 20 emit b, and on frame 50, complete. • '--(abc)-|': on frame 20, emit a, b, and c, then on frame 40 complete • '-----(a|)': on frame 50, emit a and complete.
  • 23. SUBSCRIPTION MARBLE SYNTAX • "-" time: 10 "frames" of the passage. • "^" subscription point: shows the point in time at which a subscription happen. • "!" unsubscription point: shows the point in time at which a subscription is unsubscribed.
  • 26. CONTACT • GitHub - https://github/iliaidakiev (/slides/ - list of future and past events) • Twitter - @ilia_idakiev