SlideShare a Scribd company logo
Some new features of async
test in angular
@JiaLiPassion
自己紹介
● 名前: 李嘉
● 会社: 利達ソフト
● Zone.js: Collaborator
● Angular: Contributor
● Twitter: @jialipassion
● Github: JiaLiPassion
Agenda
● Async/fakeAsync
● FakeAsync
○ Date.now()
○ jasmine.clock()
○ Rxjs.scheduler (delayなど)
● Async
○ Pending Non Resolved Promiseを待つ
○ async beforeEach + async itをサポート(Bug改修)
● 全体
○ Jasmine 2.9 & 3.x サポート
○ Mocha 5.x サポート
● そのた
async
it('should show quote after getQuote (async)', async(() => {
asyncOpertion();
fixture.whenStable().then(() => {
// all async tasks finished
expect(quoteEl.textContent).toBe(testQuote);
});
}));
fakeAsync: setTimeout/Interval/requestAnimationFrame/Promise
it('should show quote after getQuote (fakeAsync)', fakeAsync(() => {
asyncOpertion();
tick();
expect(quoteEl.textContent).toBe(testQuote);
}));
fakeAsync: Date.now()
it('should show quote after getQuote (fakeAsync)', fakeAsync(() => {
const start = Date.now();
tick(100);
const end = Date.now();
expect(end - start).toBe(100);
}));
FakeAsync: jasmine.clock() -> auto fakeAsync
beforeEach(() => {
jasmine.clock().install();
});
afterEach(() => {
jasmine.clock().uninstall();
});
it('should get date diff correctly', () => { // we don't need fakeAsync here.
// automatically run into fake async zone, because jasmine.clock() is installed.
const start = Date.now();
jasmine.clock().tick(100);
const end = Date.now();
expect(end - start).toBe(100);
});
FakeAsync: rxjs scheduler
it('should show quote after getQuote (fakeAsync)', fakeAsync(() => {
observable.delay(1000).subscribe(v => {
result = v;
});
expect(result).toBeNull();
testZoneSpec.tick(1000);
expect(result).toBe('hello');
}));
Async: Pending non resolved promise.then
it('should fail', async(() => {
const promise = new Promise((res, rej) => {
jsonp(url, res); // where jsonp is not zone aware
});
promise.then(() => {
expect(false).toBe(true);
});
}));
Async:async beforeEach + async it
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
}).compileComponents();
}));
it('simple timeout', async(() => {
setTimeout(() => {
expect(true).toBe(true);
}, 200);
}));
Jasmine 2.9 ~ 3.x, mocha 5.x support
fakeAsync: support more async operations
// tell fakeAsync should support HTMLCanvasElement.toBlob
window['__zone_symbol__FakeAsyncTestMacroTask'] = [{
source: 'HTMLCanvasElement.toBlob',
callbackArgs: [{size: 100}] // the test blob data which will be passed back to
callback
}];
Zone.js 0.8.21
Don’t call done in async/fakeAsync
it('should show quote after getQuote (async)', async((done: DoneFn) => {
asyncOpertion(() => {
doneFn(); // doneFn is undefined
});
}));
Don’t return promise in async
it('should show quote after getQuote (async)', async((done: DoneFn) => {
return new Promise((res, rej) => {
asyncOperation(res);
});
}));
Sync operation in async
it('sync', async() => {
const a = 1 + 1;
}));
it('sync', async() => {
btn.addEventListener(‘click’, listener);
}));
Next...
1. Rename async -> ?
2. async should wait for pending observable.
3. fixture.detectChange できるだけ自動実行 ?
4. Better timeout message
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
--Pendng async tasks are: [type: macroTask, source: setTimeout, args: {handleId:3,isPeriodic:false,delay:10000,args:[]}
Ad

More Related Content

What's hot (20)

The Ring programming language version 1.9 book - Part 92 of 210
The Ring programming language version 1.9 book - Part 92 of 210The Ring programming language version 1.9 book - Part 92 of 210
The Ring programming language version 1.9 book - Part 92 of 210
Mahmoud Samir Fayed
 
GPerf Using Jesque
GPerf Using JesqueGPerf Using Jesque
GPerf Using Jesque
ctoestreich
 
Theorical 1
Theorical 1Theorical 1
Theorical 1
everblut
 
Asynchronous development in JavaScript
Asynchronous development  in JavaScriptAsynchronous development  in JavaScript
Asynchronous development in JavaScript
Amitai Barnea
 
Promises in JavaScript
Promises in JavaScriptPromises in JavaScript
Promises in JavaScript
Revath S Kumar
 
Игорь Фесенко "Web Apps Performance & JavaScript Compilers"
Игорь Фесенко "Web Apps Performance & JavaScript Compilers"Игорь Фесенко "Web Apps Performance & JavaScript Compilers"
Игорь Фесенко "Web Apps Performance & JavaScript Compilers"
Fwdays
 
Teorical 1
Teorical 1Teorical 1
Teorical 1
everblut
 
Scalable Angular 2 Application Architecture
Scalable Angular 2 Application ArchitectureScalable Angular 2 Application Architecture
Scalable Angular 2 Application Architecture
FDConf
 
Debugging & profiling node.js
Debugging & profiling node.jsDebugging & profiling node.js
Debugging & profiling node.js
tomasperezv
 
React native-firebase startup-mtup
React native-firebase startup-mtupReact native-firebase startup-mtup
React native-firebase startup-mtup
t k
 
V8 javascript engine for フロントエンドデベロッパー
V8 javascript engine for フロントエンドデベロッパーV8 javascript engine for フロントエンドデベロッパー
V8 javascript engine for フロントエンドデベロッパー
Taketoshi 青野健利
 
Unbounded
UnboundedUnbounded
Unbounded
Ever Blut
 
Unbounded
UnboundedUnbounded
Unbounded
Ever Blut
 
Rntb20200805
Rntb20200805Rntb20200805
Rntb20200805
t k
 
Async programming on NET
Async programming on NETAsync programming on NET
Async programming on NET
yuyijq
 
Async Web QA
Async Web QAAsync Web QA
Async Web QA
Vlad Maniak
 
Run Node Run
Run Node RunRun Node Run
Run Node Run
Kevin Swiber
 
Java Programs
Java ProgramsJava Programs
Java Programs
Seetharamaiah Vadde
 
人間では判定できない101すくみじゃんけんをコンピュータに判定させたい for Keras.js
人間では判定できない101すくみじゃんけんをコンピュータに判定させたい for Keras.js人間では判定できない101すくみじゃんけんをコンピュータに判定させたい for Keras.js
人間では判定できない101すくみじゃんけんをコンピュータに判定させたい for Keras.js
KatsuyaENDOH
 
Service worker: discover the next web game changer
Service worker: discover the next web game changerService worker: discover the next web game changer
Service worker: discover the next web game changer
Sandro Paganotti
 
The Ring programming language version 1.9 book - Part 92 of 210
The Ring programming language version 1.9 book - Part 92 of 210The Ring programming language version 1.9 book - Part 92 of 210
The Ring programming language version 1.9 book - Part 92 of 210
Mahmoud Samir Fayed
 
GPerf Using Jesque
GPerf Using JesqueGPerf Using Jesque
GPerf Using Jesque
ctoestreich
 
Theorical 1
Theorical 1Theorical 1
Theorical 1
everblut
 
Asynchronous development in JavaScript
Asynchronous development  in JavaScriptAsynchronous development  in JavaScript
Asynchronous development in JavaScript
Amitai Barnea
 
Promises in JavaScript
Promises in JavaScriptPromises in JavaScript
Promises in JavaScript
Revath S Kumar
 
Игорь Фесенко "Web Apps Performance & JavaScript Compilers"
Игорь Фесенко "Web Apps Performance & JavaScript Compilers"Игорь Фесенко "Web Apps Performance & JavaScript Compilers"
Игорь Фесенко "Web Apps Performance & JavaScript Compilers"
Fwdays
 
Teorical 1
Teorical 1Teorical 1
Teorical 1
everblut
 
Scalable Angular 2 Application Architecture
Scalable Angular 2 Application ArchitectureScalable Angular 2 Application Architecture
Scalable Angular 2 Application Architecture
FDConf
 
Debugging & profiling node.js
Debugging & profiling node.jsDebugging & profiling node.js
Debugging & profiling node.js
tomasperezv
 
React native-firebase startup-mtup
React native-firebase startup-mtupReact native-firebase startup-mtup
React native-firebase startup-mtup
t k
 
V8 javascript engine for フロントエンドデベロッパー
V8 javascript engine for フロントエンドデベロッパーV8 javascript engine for フロントエンドデベロッパー
V8 javascript engine for フロントエンドデベロッパー
Taketoshi 青野健利
 
Rntb20200805
Rntb20200805Rntb20200805
Rntb20200805
t k
 
Async programming on NET
Async programming on NETAsync programming on NET
Async programming on NET
yuyijq
 
人間では判定できない101すくみじゃんけんをコンピュータに判定させたい for Keras.js
人間では判定できない101すくみじゃんけんをコンピュータに判定させたい for Keras.js人間では判定できない101すくみじゃんけんをコンピュータに判定させたい for Keras.js
人間では判定できない101すくみじゃんけんをコンピュータに判定させたい for Keras.js
KatsuyaENDOH
 
Service worker: discover the next web game changer
Service worker: discover the next web game changerService worker: discover the next web game changer
Service worker: discover the next web game changer
Sandro Paganotti
 

Similar to New feature of async fakeAsync test in angular (20)

Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
Garrett Welson
 
Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0
Oscar Renalias
 
Angular promises and http
Angular promises and httpAngular promises and http
Angular promises and http
Alexe Bogdan
 
Async Testing giving you a sinking feeling
Async Testing giving you a sinking feelingAsync Testing giving you a sinking feeling
Async Testing giving you a sinking feeling
Erin Zimmer
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScript
jnewmanux
 
Rxjs marble-testing
Rxjs marble-testingRxjs marble-testing
Rxjs marble-testing
Christoffer Noring
 
Async js - Nemetschek Presentaion @ HackBulgaria
Async js - Nemetschek Presentaion @ HackBulgariaAsync js - Nemetschek Presentaion @ HackBulgaria
Async js - Nemetschek Presentaion @ HackBulgaria
HackBulgaria
 
Call stack, event loop and async programming
Call stack, event loop and async programmingCall stack, event loop and async programming
Call stack, event loop and async programming
Masters Academy
 
A real-world example of Functional Programming with fp-ts - no experience req...
A real-world example of Functional Programming with fp-ts - no experience req...A real-world example of Functional Programming with fp-ts - no experience req...
A real-world example of Functional Programming with fp-ts - no experience req...
Frederick Fogerty
 
The evolution of java script asynchronous calls
The evolution of java script asynchronous callsThe evolution of java script asynchronous calls
The evolution of java script asynchronous calls
Huy Hoàng Phạm
 
The Promised Land (in Angular)
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)
Domenic Denicola
 
Promises are so passé - Tim Perry - Codemotion Milan 2016
Promises are so passé - Tim Perry - Codemotion Milan 2016Promises are so passé - Tim Perry - Codemotion Milan 2016
Promises are so passé - Tim Perry - Codemotion Milan 2016
Codemotion
 
asyncjavascript.pptxdgdsgdffgfdgfgfgfdgfdgf
asyncjavascript.pptxdgdsgdffgfdgfgfgfdgfdgfasyncjavascript.pptxdgdsgdffgfdgfgfgfdgfdgf
asyncjavascript.pptxdgdsgdffgfdgfgfgfdgfdgf
zmulani8
 
Rxjs ngvikings
Rxjs ngvikingsRxjs ngvikings
Rxjs ngvikings
Christoffer Noring
 
Unit testing with mocha
Unit testing with mochaUnit testing with mocha
Unit testing with mocha
Revath S Kumar
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testing
Visual Engineering
 
Promise: async programming hero
Promise: async programming heroPromise: async programming hero
Promise: async programming hero
The Software House
 
Rxjs swetugg
Rxjs swetuggRxjs swetugg
Rxjs swetugg
Christoffer Noring
 
Promises, promises, and then observables
Promises, promises, and then observablesPromises, promises, and then observables
Promises, promises, and then observables
Stefan Charsley
 
Asynchronen Code testen
Asynchronen Code testenAsynchronen Code testen
Asynchronen Code testen
ndrssmn
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
Garrett Welson
 
Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0
Oscar Renalias
 
Angular promises and http
Angular promises and httpAngular promises and http
Angular promises and http
Alexe Bogdan
 
Async Testing giving you a sinking feeling
Async Testing giving you a sinking feelingAsync Testing giving you a sinking feeling
Async Testing giving you a sinking feeling
Erin Zimmer
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScript
jnewmanux
 
Async js - Nemetschek Presentaion @ HackBulgaria
Async js - Nemetschek Presentaion @ HackBulgariaAsync js - Nemetschek Presentaion @ HackBulgaria
Async js - Nemetschek Presentaion @ HackBulgaria
HackBulgaria
 
Call stack, event loop and async programming
Call stack, event loop and async programmingCall stack, event loop and async programming
Call stack, event loop and async programming
Masters Academy
 
A real-world example of Functional Programming with fp-ts - no experience req...
A real-world example of Functional Programming with fp-ts - no experience req...A real-world example of Functional Programming with fp-ts - no experience req...
A real-world example of Functional Programming with fp-ts - no experience req...
Frederick Fogerty
 
The evolution of java script asynchronous calls
The evolution of java script asynchronous callsThe evolution of java script asynchronous calls
The evolution of java script asynchronous calls
Huy Hoàng Phạm
 
The Promised Land (in Angular)
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)
Domenic Denicola
 
Promises are so passé - Tim Perry - Codemotion Milan 2016
Promises are so passé - Tim Perry - Codemotion Milan 2016Promises are so passé - Tim Perry - Codemotion Milan 2016
Promises are so passé - Tim Perry - Codemotion Milan 2016
Codemotion
 
asyncjavascript.pptxdgdsgdffgfdgfgfgfdgfdgf
asyncjavascript.pptxdgdsgdffgfdgfgfgfdgfdgfasyncjavascript.pptxdgdsgdffgfdgfgfgfdgfdgf
asyncjavascript.pptxdgdsgdffgfdgfgfgfdgfdgf
zmulani8
 
Unit testing with mocha
Unit testing with mochaUnit testing with mocha
Unit testing with mocha
Revath S Kumar
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testing
Visual Engineering
 
Promise: async programming hero
Promise: async programming heroPromise: async programming hero
Promise: async programming hero
The Software House
 
Promises, promises, and then observables
Promises, promises, and then observablesPromises, promises, and then observables
Promises, promises, and then observables
Stefan Charsley
 
Asynchronen Code testen
Asynchronen Code testenAsynchronen Code testen
Asynchronen Code testen
ndrssmn
 
Ad

Recently uploaded (20)

GDS SYSTEM | GLOBAL DISTRIBUTION SYSTEM
GDS SYSTEM | GLOBAL  DISTRIBUTION SYSTEMGDS SYSTEM | GLOBAL  DISTRIBUTION SYSTEM
GDS SYSTEM | GLOBAL DISTRIBUTION SYSTEM
philipnathen82
 
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game DevelopmentBest Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Juego Studios
 
How To Develop A Cryptocurrency Exchange - Slideshare.pptx
How To Develop A Cryptocurrency Exchange - Slideshare.pptxHow To Develop A Cryptocurrency Exchange - Slideshare.pptx
How To Develop A Cryptocurrency Exchange - Slideshare.pptx
laravinson24
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Innovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at allInnovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at all
ayeshakanwal75
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Implementing promises with typescripts, step by step
Implementing promises with typescripts, step by stepImplementing promises with typescripts, step by step
Implementing promises with typescripts, step by step
Ran Wahle
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Download Canva Pro 2025 PC Crack Latest Version .
Download Canva Pro 2025 PC Crack Latest Version .Download Canva Pro 2025 PC Crack Latest Version .
Download Canva Pro 2025 PC Crack Latest Version .
sadiyabibi60507
 
A Deep Dive into Odoo CRM: Lead Management, Automation & More
A Deep Dive into Odoo CRM: Lead Management, Automation & MoreA Deep Dive into Odoo CRM: Lead Management, Automation & More
A Deep Dive into Odoo CRM: Lead Management, Automation & More
SatishKumar2651
 
ML-Topic1A.ppteeweqeqeqeqeqeqwewqqwwqeeqeqw
ML-Topic1A.ppteeweqeqeqeqeqeqwewqqwwqeeqeqwML-Topic1A.ppteeweqeqeqeqeqeqwewqqwwqeeqeqw
ML-Topic1A.ppteeweqeqeqeqeqeqwewqqwwqeeqeqw
YumnaShahzaad
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
Lionel Briand
 
AI in Business Software: Smarter Systems or Hidden Risks?
AI in Business Software: Smarter Systems or Hidden Risks?AI in Business Software: Smarter Systems or Hidden Risks?
AI in Business Software: Smarter Systems or Hidden Risks?
Amara Nielson
 
Cryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptxCryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptx
riyageorge2024
 
GDS SYSTEM | GLOBAL DISTRIBUTION SYSTEM
GDS SYSTEM | GLOBAL  DISTRIBUTION SYSTEMGDS SYSTEM | GLOBAL  DISTRIBUTION SYSTEM
GDS SYSTEM | GLOBAL DISTRIBUTION SYSTEM
philipnathen82
 
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game DevelopmentBest Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Juego Studios
 
How To Develop A Cryptocurrency Exchange - Slideshare.pptx
How To Develop A Cryptocurrency Exchange - Slideshare.pptxHow To Develop A Cryptocurrency Exchange - Slideshare.pptx
How To Develop A Cryptocurrency Exchange - Slideshare.pptx
laravinson24
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Innovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at allInnovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at all
ayeshakanwal75
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Implementing promises with typescripts, step by step
Implementing promises with typescripts, step by stepImplementing promises with typescripts, step by step
Implementing promises with typescripts, step by step
Ran Wahle
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Download Canva Pro 2025 PC Crack Latest Version .
Download Canva Pro 2025 PC Crack Latest Version .Download Canva Pro 2025 PC Crack Latest Version .
Download Canva Pro 2025 PC Crack Latest Version .
sadiyabibi60507
 
A Deep Dive into Odoo CRM: Lead Management, Automation & More
A Deep Dive into Odoo CRM: Lead Management, Automation & MoreA Deep Dive into Odoo CRM: Lead Management, Automation & More
A Deep Dive into Odoo CRM: Lead Management, Automation & More
SatishKumar2651
 
ML-Topic1A.ppteeweqeqeqeqeqeqwewqqwwqeeqeqw
ML-Topic1A.ppteeweqeqeqeqeqeqwewqqwwqeeqeqwML-Topic1A.ppteeweqeqeqeqeqeqwewqqwwqeeqeqw
ML-Topic1A.ppteeweqeqeqeqeqeqwewqqwwqeeqeqw
YumnaShahzaad
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
FlakyFix: Using Large Language Models for Predicting Flaky Test Fix Categorie...
Lionel Briand
 
AI in Business Software: Smarter Systems or Hidden Risks?
AI in Business Software: Smarter Systems or Hidden Risks?AI in Business Software: Smarter Systems or Hidden Risks?
AI in Business Software: Smarter Systems or Hidden Risks?
Amara Nielson
 
Cryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptxCryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptx
riyageorge2024
 
Ad

New feature of async fakeAsync test in angular

  • 1. Some new features of async test in angular @JiaLiPassion
  • 2. 自己紹介 ● 名前: 李嘉 ● 会社: 利達ソフト ● Zone.js: Collaborator ● Angular: Contributor ● Twitter: @jialipassion ● Github: JiaLiPassion
  • 3. Agenda ● Async/fakeAsync ● FakeAsync ○ Date.now() ○ jasmine.clock() ○ Rxjs.scheduler (delayなど) ● Async ○ Pending Non Resolved Promiseを待つ ○ async beforeEach + async itをサポート(Bug改修) ● 全体 ○ Jasmine 2.9 & 3.x サポート ○ Mocha 5.x サポート ● そのた
  • 4. async it('should show quote after getQuote (async)', async(() => { asyncOpertion(); fixture.whenStable().then(() => { // all async tasks finished expect(quoteEl.textContent).toBe(testQuote); }); }));
  • 5. fakeAsync: setTimeout/Interval/requestAnimationFrame/Promise it('should show quote after getQuote (fakeAsync)', fakeAsync(() => { asyncOpertion(); tick(); expect(quoteEl.textContent).toBe(testQuote); }));
  • 6. fakeAsync: Date.now() it('should show quote after getQuote (fakeAsync)', fakeAsync(() => { const start = Date.now(); tick(100); const end = Date.now(); expect(end - start).toBe(100); }));
  • 7. FakeAsync: jasmine.clock() -> auto fakeAsync beforeEach(() => { jasmine.clock().install(); }); afterEach(() => { jasmine.clock().uninstall(); }); it('should get date diff correctly', () => { // we don't need fakeAsync here. // automatically run into fake async zone, because jasmine.clock() is installed. const start = Date.now(); jasmine.clock().tick(100); const end = Date.now(); expect(end - start).toBe(100); });
  • 8. FakeAsync: rxjs scheduler it('should show quote after getQuote (fakeAsync)', fakeAsync(() => { observable.delay(1000).subscribe(v => { result = v; }); expect(result).toBeNull(); testZoneSpec.tick(1000); expect(result).toBe('hello'); }));
  • 9. Async: Pending non resolved promise.then it('should fail', async(() => { const promise = new Promise((res, rej) => { jsonp(url, res); // where jsonp is not zone aware }); promise.then(() => { expect(false).toBe(true); }); }));
  • 10. Async:async beforeEach + async it beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ AppComponent ], }).compileComponents(); })); it('simple timeout', async(() => { setTimeout(() => { expect(true).toBe(true); }, 200); }));
  • 11. Jasmine 2.9 ~ 3.x, mocha 5.x support
  • 12. fakeAsync: support more async operations // tell fakeAsync should support HTMLCanvasElement.toBlob window['__zone_symbol__FakeAsyncTestMacroTask'] = [{ source: 'HTMLCanvasElement.toBlob', callbackArgs: [{size: 100}] // the test blob data which will be passed back to callback }];
  • 14. Don’t call done in async/fakeAsync it('should show quote after getQuote (async)', async((done: DoneFn) => { asyncOpertion(() => { doneFn(); // doneFn is undefined }); }));
  • 15. Don’t return promise in async it('should show quote after getQuote (async)', async((done: DoneFn) => { return new Promise((res, rej) => { asyncOperation(res); }); }));
  • 16. Sync operation in async it('sync', async() => { const a = 1 + 1; })); it('sync', async() => { btn.addEventListener(‘click’, listener); }));
  • 17. Next... 1. Rename async -> ? 2. async should wait for pending observable. 3. fixture.detectChange できるだけ自動実行 ? 4. Better timeout message Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. --Pendng async tasks are: [type: macroTask, source: setTimeout, args: {handleId:3,isPeriodic:false,delay:10000,args:[]}