SlideShare a Scribd company logo
1 of 21
•
•
•
•
Resources & Tools
•

•

yo angular:route foo

•

•

•
•

•

•

grunt build

•

•

bower install

•
•

•

npm install –g yo
return {…};
new svc();
new pro().$get();
Two-way binding
Uses implicit $watches

expect($scope.$$watchers.length)
.toBe(4);
$scope.$watch('num', function() {});

expect($scope.$$watchers.length).toBe(5);
View is updated by $digest

expect(view.find('first').html()) .toBe('random stuff');

$scope.$digest();
expect(view.find('first').html()) .not.toBe('random stuff');
expect(view.find('first').html()).toBe(„2‟);
You must $apply yourself
(outside of Angular land)

expect(view.find('fourth').html()).toBeFalsy();
view.find('fourth').on("click", function() {
$scope.value = 10;
});
view.find('fourth')[0].click();

.toBeFalsy();
expect(view.find('fourth').html())
You must $apply yourself
(outside of Angular land)

expect(view.find('fourth').html()).toBeFalsy();
view.find('fourth').on("click", function() {
$scope.value = 10;
$scope.apply();
});
view.find('fourth')[0].click();
expect(view.find('fourth').html()).toBe(„10‟);
You must $apply yourself
(outside of Angular land)

expect(view.find('fourth').html()).toBeFalsy();
browserTrigger(view.find('div'), "click");

expect(view.find('fourth').html()).toBe('15');
$apply and $digest
Uses dirty checking
$scope.guy = {};
var watch = jasmine.createSpyObj('watch',
['obj', 'property', 'deepObj']);
$scope.$watch('guy', watch.obj);
$scope.$watch('guy.name', watch.property);
$scope.$watch('guy', watch.deepObj, true); // use angular.equals()
$scope.$digest();
watch.obj.reset();
watch.property.reset();
watch.deepObj.reset();
$scope.$apply(function() {
$scope.guy.name = 'fred';
});
expect(watch.obj).not.toHaveBeenCalled();
expect(watch.property).toHaveBeenCalled();
expect(watch.deepObj).toHaveBeenCalled();
$digest loop
var digestCount = 0;
$scope.test = 1;
$scope.$watch('test', function()
{
if($scope.test < 4) {
$scope.test++;
}
});
$scope.$watch(function() {
digestCount++;
});
$scope.$digest();
expect(digestCount)
.toBe(4);
$digest infinite loop
$scope.getPeople = function() {
return [
{name: "john"},
{name: "fred"}
];
};
$compile(template)($scope);
expect(function() {
$scope.$digest();
}).toThrow();
$digest loop
var people = [
{name: "john"},
{name: "fred"}
];
$scope.getPeople = function() {
return people;
};
view = $compile(template)($scope);
$scope.$digest();
expect(view.find('person').length)
.toBe(2);
Use the dot

$scope.people = [
{name:”fred”},
{name: “john”}
];
$scope.personOfDay = “fred”;
expect(view.find("div").length).toBe(2);
expect(view.find("pod").html()).toBe("fred");
browserTrigger(view.find("button.john.pod"), "click");
.toBe("fred");
expect(view.find("pod").html())
Use the dot

$scope.people = [
{name: ”fred”},
{name: “john”}
];
$scope.personOfDay = {
current: “fred”
};
expect(view.find("div").length).toBe(2);
expect(view.find("pod").html()).toBe("fred");
browserTrigger(view.find("button.john.pod"), "click");
expect(view.find("pod").html()).toBe(“john”);
I promise this is the end
var link = “https://github.com/angular/angular.js/” +
“commit/117f4ddba96a12224d878cbf9c6846f4c9954971”
Questions?

More Related Content

What's hot

Legacy applications - 4Developes konferencja, Piotr Pasich
Legacy applications  - 4Developes konferencja, Piotr PasichLegacy applications  - 4Developes konferencja, Piotr Pasich
Legacy applications - 4Developes konferencja, Piotr Pasich
Piotr Pasich
 

What's hot (12)

Copy/paste detector for source code on javascript
Copy/paste detector for source code on javascript Copy/paste detector for source code on javascript
Copy/paste detector for source code on javascript
 
Ricky Bobby's World
Ricky Bobby's WorldRicky Bobby's World
Ricky Bobby's World
 
基盤加工機講習資料2019
基盤加工機講習資料2019基盤加工機講習資料2019
基盤加工機講習資料2019
 
Your Second iPhone App - Code Listings
Your Second iPhone App - Code ListingsYour Second iPhone App - Code Listings
Your Second iPhone App - Code Listings
 
Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6
 
Ns2 ns3 training in mohali
Ns2 ns3 training in mohaliNs2 ns3 training in mohali
Ns2 ns3 training in mohali
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges
 
Cakephpstudy5 hacks
Cakephpstudy5 hacksCakephpstudy5 hacks
Cakephpstudy5 hacks
 
Hashing endereçamento aberto - main
Hashing endereçamento aberto - mainHashing endereçamento aberto - main
Hashing endereçamento aberto - main
 
Legacy applications - 4Developes konferencja, Piotr Pasich
Legacy applications  - 4Developes konferencja, Piotr PasichLegacy applications  - 4Developes konferencja, Piotr Pasich
Legacy applications - 4Developes konferencja, Piotr Pasich
 
Sol10
Sol10Sol10
Sol10
 
Jakub Kulhán - ReactPHP + Symfony = PROFIT (1. sraz přátel Symfony v Praze)
Jakub Kulhán - ReactPHP + Symfony = PROFIT (1. sraz přátel Symfony v Praze)Jakub Kulhán - ReactPHP + Symfony = PROFIT (1. sraz přátel Symfony v Praze)
Jakub Kulhán - ReactPHP + Symfony = PROFIT (1. sraz přátel Symfony v Praze)
 

Similar to Angular gotchas

JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 
Learning jquery-in-30-minutes-1195942580702664-3
Learning jquery-in-30-minutes-1195942580702664-3Learning jquery-in-30-minutes-1195942580702664-3
Learning jquery-in-30-minutes-1195942580702664-3
luckysb16
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
Fabien Potencier
 
Всеволод Струкчинский: Node.js
Всеволод Струкчинский: Node.jsВсеволод Струкчинский: Node.js
Всеволод Струкчинский: Node.js
Yandex
 
Javascript Continues Integration in Jenkins with AngularJS
Javascript Continues Integration in Jenkins with AngularJSJavascript Continues Integration in Jenkins with AngularJS
Javascript Continues Integration in Jenkins with AngularJS
Ladislav Prskavec
 
ISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみたISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみた
memememomo
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
Seri Moth
 

Similar to Angular gotchas (20)

Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!
 
Webエンジニアから見たiOS5
Webエンジニアから見たiOS5Webエンジニアから見たiOS5
Webエンジニアから見たiOS5
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
Learning jquery-in-30-minutes-1195942580702664-3
Learning jquery-in-30-minutes-1195942580702664-3Learning jquery-in-30-minutes-1195942580702664-3
Learning jquery-in-30-minutes-1195942580702664-3
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript Everywhere
 
GIT, RVM, FIRST HEROKU APP
GIT, RVM, FIRST HEROKU APPGIT, RVM, FIRST HEROKU APP
GIT, RVM, FIRST HEROKU APP
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introductionAngularjs - Unit testing introduction
Angularjs - Unit testing introduction
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
 
Всеволод Струкчинский: Node.js
Всеволод Струкчинский: Node.jsВсеволод Струкчинский: Node.js
Всеволод Струкчинский: Node.js
 
Node.js for PHP developers
Node.js for PHP developersNode.js for PHP developers
Node.js for PHP developers
 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
 
Javascript Continues Integration in Jenkins with AngularJS
Javascript Continues Integration in Jenkins with AngularJSJavascript Continues Integration in Jenkins with AngularJS
Javascript Continues Integration in Jenkins with AngularJS
 
Unit Testing from Setup to Deployment
Unit Testing from Setup to DeploymentUnit Testing from Setup to Deployment
Unit Testing from Setup to Deployment
 
Web Scraping with Python
Web Scraping with PythonWeb Scraping with Python
Web Scraping with Python
 
Iphone course 2
Iphone course 2Iphone course 2
Iphone course 2
 
ISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみたISUCONアプリを Pythonで書いてみた
ISUCONアプリを Pythonで書いてみた
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 

Recently uploaded

Recently uploaded (20)

JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

Angular gotchas

  • 1.
  • 2.
  • 3.
  • 5. Resources & Tools • • yo angular:route foo • • • • • • grunt build • • bower install • • • npm install –g yo
  • 8. Uses implicit $watches expect($scope.$$watchers.length) .toBe(4); $scope.$watch('num', function() {}); expect($scope.$$watchers.length).toBe(5);
  • 9. View is updated by $digest expect(view.find('first').html()) .toBe('random stuff'); $scope.$digest(); expect(view.find('first').html()) .not.toBe('random stuff'); expect(view.find('first').html()).toBe(„2‟);
  • 10. You must $apply yourself (outside of Angular land) expect(view.find('fourth').html()).toBeFalsy(); view.find('fourth').on("click", function() { $scope.value = 10; }); view.find('fourth')[0].click(); .toBeFalsy(); expect(view.find('fourth').html())
  • 11. You must $apply yourself (outside of Angular land) expect(view.find('fourth').html()).toBeFalsy(); view.find('fourth').on("click", function() { $scope.value = 10; $scope.apply(); }); view.find('fourth')[0].click(); expect(view.find('fourth').html()).toBe(„10‟);
  • 12. You must $apply yourself (outside of Angular land) expect(view.find('fourth').html()).toBeFalsy(); browserTrigger(view.find('div'), "click"); expect(view.find('fourth').html()).toBe('15');
  • 14. Uses dirty checking $scope.guy = {}; var watch = jasmine.createSpyObj('watch', ['obj', 'property', 'deepObj']); $scope.$watch('guy', watch.obj); $scope.$watch('guy.name', watch.property); $scope.$watch('guy', watch.deepObj, true); // use angular.equals() $scope.$digest(); watch.obj.reset(); watch.property.reset(); watch.deepObj.reset(); $scope.$apply(function() { $scope.guy.name = 'fred'; }); expect(watch.obj).not.toHaveBeenCalled(); expect(watch.property).toHaveBeenCalled(); expect(watch.deepObj).toHaveBeenCalled();
  • 15. $digest loop var digestCount = 0; $scope.test = 1; $scope.$watch('test', function() { if($scope.test < 4) { $scope.test++; } }); $scope.$watch(function() { digestCount++; }); $scope.$digest(); expect(digestCount) .toBe(4);
  • 16. $digest infinite loop $scope.getPeople = function() { return [ {name: "john"}, {name: "fred"} ]; }; $compile(template)($scope); expect(function() { $scope.$digest(); }).toThrow();
  • 17. $digest loop var people = [ {name: "john"}, {name: "fred"} ]; $scope.getPeople = function() { return people; }; view = $compile(template)($scope); $scope.$digest(); expect(view.find('person').length) .toBe(2);
  • 18. Use the dot $scope.people = [ {name:”fred”}, {name: “john”} ]; $scope.personOfDay = “fred”; expect(view.find("div").length).toBe(2); expect(view.find("pod").html()).toBe("fred"); browserTrigger(view.find("button.john.pod"), "click"); .toBe("fred"); expect(view.find("pod").html())
  • 19. Use the dot $scope.people = [ {name: ”fred”}, {name: “john”} ]; $scope.personOfDay = { current: “fred” }; expect(view.find("div").length).toBe(2); expect(view.find("pod").html()).toBe("fred"); browserTrigger(view.find("button.john.pod"), "click"); expect(view.find("pod").html()).toBe(“john”);
  • 20. I promise this is the end var link = “https://github.com/angular/angular.js/” + “commit/117f4ddba96a12224d878cbf9c6846f4c9954971”