Test-Driven Development of AngularJS ApplicationsFITC
Save 10% off ANY FITC event with discount code 'slideshare'
See our upcoming events at www.fitc.ca
OVERVIEW
AngularJS is an open-source JavaScript framework, maintained by Google, that simplifies development of single-page applications. This session will provide an overview of AngularJS framework and demonstrate test-driven development of single-page applications.
In this session Andy will present a walkthrough of Angular’s core features such as dependency injector and directives. He will showcase a test-driven development of AngularJS applications using Jasmine and explain Angular’s data bindings that allow for creation of views and controllers that update automatically in response to data changes. He will also demo Angular’s deep linking and front-end validations and present integration with Ruby On Rails back end using AngularJS AJAX abstractions. Finally, Andy will utilize AngularJS directives and components to create reusable UI elements.
In summary, AngularJS is a great framework for creating complex single-page applications. Attendees will leave the talk with a solid understanding of Angular’s test-driven development process.
Test-Driven Development of AngularJS ApplicationsFITC
Save 10% off ANY FITC event with discount code 'slideshare'
See our upcoming events at www.fitc.ca
OVERVIEW
AngularJS is an open-source JavaScript framework, maintained by Google, that simplifies development of single-page applications. This session will provide an overview of AngularJS framework and demonstrate test-driven development of single-page applications.
In this session Andy will present a walkthrough of Angular’s core features such as dependency injector and directives. He will showcase a test-driven development of AngularJS applications using Jasmine and explain Angular’s data bindings that allow for creation of views and controllers that update automatically in response to data changes. He will also demo Angular’s deep linking and front-end validations and present integration with Ruby On Rails back end using AngularJS AJAX abstractions. Finally, Andy will utilize AngularJS directives and components to create reusable UI elements.
In summary, AngularJS is a great framework for creating complex single-page applications. Attendees will leave the talk with a solid understanding of Angular’s test-driven development process.
For a number of years now we have been hearing about all of the benefits that automated unit testing provides like increasing our quality, catching errors earlier, ensuring that all developers are testing in the same manner and deploying updates with high confidence that nothing will break. Testing a Web UI though was difficult and fragile which meant that typically we had no automated unit test for our Web UI. This is no longer the case with the latest release of Angular. Unit testing is now a first class citizen in Angular.
Out of the box, the project generated by the Angular CLI has unit testing setup with Karma and Jasmine and includes sample tests. Generating new components, services, and pipes includes the unit test Spec file already wired up. Thus allowing you to focus on writing your unit tests and not on the infrastructure needed to get them running. The barriers to writing unit test have been destroyed.
This talk will walk through getting started unit testing your Angular components, services, and pipes. Along the way I will share the tips and tricks that I have learned as I have implemented unit testing on my Angular projects at a Fortune 100 company. You will walk away ready to immediately implement unit testing on your Angular project.
Angular Unit Testing from the TrenchesJustin James
For a number of years now we have been hearing about all of the benefits that automated unit testing provides like increasing our quality, catching errors earlier, ensuring that all developers are testing in the same manner and deploying updates with high confidence that nothing will break. Testing a Web UI though was difficult and fragile which meant that typically we had no automated unit test for our Web UI. This is no longer the case with the latest release of Angular. Unit testing is now a first class citizen in Angular.
Out of the box, the project generated by the Angular CLI has unit testing setup with Karma and Jasmine and includes sample tests. Generating new components, services, and pipes includes the unit test Spec file already wired up. Thus allowing you to focus on writing your unit tests and not on the infrastructure needed to get them running. The barriers to writing unit test have been destroyed.
This talk will walk through getting started unit testing your Angular components, services, and pipes. Along the way I will share the tips and tricks that I have learned as I have implemented unit testing on my Angular projects at a Fortune 100 company. You will walk away ready to immediately implement unit testing on your Angular project.
A talk about unit testing for iOS apps. Part rambling introduction to test driven development, part examples of certain types of tests for iOS, and a brief mention of writing your tests using Kiwi.
Advanced Jasmine - Front-End JavaScript Unit TestingLars Thorup
Code: https://github.com/larsthorup/jasmine-demo-advanced
Video: https://www.youtube.com/watch?v=g4eQplHxU18
Audio: https://www.youtube.com/watch?v=8FUwc3gZDMw
Unit testing front-end JavaScript presents its own unique set of challenges. In this session we will look at number of different techniques to tackle these challenges and make our JavaScript unit tests fast and robust. We plan to cover the following subjects:
* Mocking and spy techniques to avoid dependencies on
- Functions, methods and constructor functions
- Time (new Date())
- Timers (setTimeout, setInterval)
- Ajax requests
- The DOM
- Events
* Expressive matchers
- Jasmine-jQuery
* Structuring tests for reuse and readability
* Testing browser-specific behaviour
Given that the database, as the canonical repository of data, is the most important part of many applications, why is it that we don't write database unit tests? This talk promotes the practice of implementing tests to directly test the schema, storage, and functionality of databases.
For a number of years now we have been hearing about all of the benefits that automated unit testing provides like increasing our quality, catching errors earlier, ensuring that all developers are testing in the same manner and deploying updates with high confidence that nothing will break. Testing a Web UI though was difficult and fragile which meant that typically we had no automated unit test for our Web UI. This is no longer the case with the latest release of Angular. Unit testing is now a first class citizen in Angular.
Out of the box, the project generated by the Angular CLI has unit testing setup with Karma and Jasmine and includes sample tests. Generating new components, services, and pipes includes the unit test Spec file already wired up. Thus allowing you to focus on writing your unit tests and not on the infrastructure needed to get them running. The barriers to writing unit test have been destroyed.
This talk will walk through getting started unit testing your Angular components, services, and pipes. Along the way I will share the tips and tricks that I have learned as I have implemented unit testing on my Angular projects at a Fortune 100 company. You will walk away ready to immediately implement unit testing on your Angular project.
Angular Unit Testing from the TrenchesJustin James
For a number of years now we have been hearing about all of the benefits that automated unit testing provides like increasing our quality, catching errors earlier, ensuring that all developers are testing in the same manner and deploying updates with high confidence that nothing will break. Testing a Web UI though was difficult and fragile which meant that typically we had no automated unit test for our Web UI. This is no longer the case with the latest release of Angular. Unit testing is now a first class citizen in Angular.
Out of the box, the project generated by the Angular CLI has unit testing setup with Karma and Jasmine and includes sample tests. Generating new components, services, and pipes includes the unit test Spec file already wired up. Thus allowing you to focus on writing your unit tests and not on the infrastructure needed to get them running. The barriers to writing unit test have been destroyed.
This talk will walk through getting started unit testing your Angular components, services, and pipes. Along the way I will share the tips and tricks that I have learned as I have implemented unit testing on my Angular projects at a Fortune 100 company. You will walk away ready to immediately implement unit testing on your Angular project.
A talk about unit testing for iOS apps. Part rambling introduction to test driven development, part examples of certain types of tests for iOS, and a brief mention of writing your tests using Kiwi.
Advanced Jasmine - Front-End JavaScript Unit TestingLars Thorup
Code: https://github.com/larsthorup/jasmine-demo-advanced
Video: https://www.youtube.com/watch?v=g4eQplHxU18
Audio: https://www.youtube.com/watch?v=8FUwc3gZDMw
Unit testing front-end JavaScript presents its own unique set of challenges. In this session we will look at number of different techniques to tackle these challenges and make our JavaScript unit tests fast and robust. We plan to cover the following subjects:
* Mocking and spy techniques to avoid dependencies on
- Functions, methods and constructor functions
- Time (new Date())
- Timers (setTimeout, setInterval)
- Ajax requests
- The DOM
- Events
* Expressive matchers
- Jasmine-jQuery
* Structuring tests for reuse and readability
* Testing browser-specific behaviour
Given that the database, as the canonical repository of data, is the most important part of many applications, why is it that we don't write database unit tests? This talk promotes the practice of implementing tests to directly test the schema, storage, and functionality of databases.
الهرمينوطيقا بوصفها يقظة العيش في العالَم (تجربة مارتن هيدغر في محاضرات 1923)حسن قروق
الملخص:
منذ مطالع القرن العشرين، حسم الفيلسوف الألماني مارتن هيدغر (1889 - 1976) أمره مع (الهرمينوطيقا) عندما سعى إلى بناء رؤيته الفلسفية الجديدة بشأنها مُحدِثاً قطيعة معرفية جذرية مع تراثها وهو يستأنف قولها التجديدي على نحو فلسفي رائق جعله ينأى عن جُملة النظريات السابقة عليه بإيقاظ دلالاتها الأصلية لا بوصفها معرفة إنّما كتعرُّف وجودي أنطولوجي على العالَم؛ فالهرمينوطيقا ليست مذهباً ولا مهارة منهجية بعديَّة يمكن الذهاب إليها، بل هي سمة للوجود والموجود، وما الكائن البشري سوى كائن هرمينوطيقي بطبعه الذي له. ولذلك لا يتحدَّث هيدغر في محاضراته لعام 1923 عن الهرمينوطيقا على غرار أسلافه بوصفها نظرية للقراءة والتحليل والفهم، بل كأساس أنطولوجي وجودي يجد الكائن البشري منخرطاً فيه بالعالَم بوصفه مؤوَّلاً، ما يعني أنّ الهرمينوطيقا هي سلوك الكائن الذي يريد أن يكون ويوجد ويحضر، سلوكها كقدر أصلي له.
ISS World Prague 2010 - DPI at 40G and 100G: Moving Beyond AppliancesContinuous Computing
Featured Speaker:Mike Coward, co-Founder and CTO, Continuous Computing
When: Thursday, June 3, 2010
Time: 12:00- 12:30 p.m.
Track: Deep Packet Inspection
Topic: DPI at 40G and 100G: Moving Beyond Appliances
A brief introduction to javascript test driven development (TDD) towards several point of views by using qUnit, Karma & Jasmine, NodeJS tape module and custom frameworks.
utPLSQL offers a unit testing API for PL/SQL that is modeled on the xUnit approach. This is an old slide deck on utPLSQL so my apologies for any inconsistencies with the current utility. Note: while I created the original utPLSQL code base, I am not actively working on utPLSQL at this time. Check out github.com/utplsql for the code and project details.
Demonstrate some great aspects of Mockito. Made for Mockito v1.8.5.
All examples can be found @
https://github.com/dodozhang21/MockitoExamples
Ying Zhang (Dodo) http://pure-essence.net
Developer Tests - Things to Know (Vilnius JUG)vilniusjug
There are many great talks that discuss challenges developers face when writing software tests. In this talk let's look at test design problems that may seem to be simple but yet fundamentally important and often misunderstood even by experienced programmers.
V1.0
How often do you get a bug report that you can’t reproduce?
How often do you struggle to find the source of the bug in your code?
How can you streamline the testing process and make sure you don’t repeat the same bugs?
With Visual Studio 2010 & Team Foundation Server (TFS) 2010 there are a lot of new features for testers and developers that will solve these problems.
In this session you will learn how to: automate more, reproduce bugs easier, maintain your tests and configuration and discover problems sooner.
from Peter Gfader
First Steps with Globus Compute Multi-User EndpointsGlobus
In this presentation we will share our experiences around getting started with the Globus Compute multi-user endpoint. Working with the Pharmacology group at the University of Auckland, we have previously written an application using Globus Compute that can offload computationally expensive steps in the researcher's workflows, which they wish to manage from their familiar Windows environments, onto the NeSI (New Zealand eScience Infrastructure) cluster. Some of the challenges we have encountered were that each researcher had to set up and manage their own single-user globus compute endpoint and that the workloads had varying resource requirements (CPUs, memory and wall time) between different runs. We hope that the multi-user endpoint will help to address these challenges and share an update on our progress here.
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamtakuyayamamoto1800
In this slide, we show the simulation example and the way to compile this solver.
In this solver, the Helmholtz equation can be solved by helmholtzFoam. Also, the Helmholtz equation with uniformly dispersed bubbles can be simulated by helmholtzBubbleFoam.
Understanding Globus Data Transfers with NetSageGlobus
NetSage is an open privacy-aware network measurement, analysis, and visualization service designed to help end-users visualize and reason about large data transfers. NetSage traditionally has used a combination of passive measurements, including SNMP and flow data, as well as active measurements, mainly perfSONAR, to provide longitudinal network performance data visualization. It has been deployed by dozens of networks world wide, and is supported domestically by the Engagement and Performance Operations Center (EPOC), NSF #2328479. We have recently expanded the NetSage data sources to include logs for Globus data transfers, following the same privacy-preserving approach as for Flow data. Using the logs for the Texas Advanced Computing Center (TACC) as an example, this talk will walk through several different example use cases that NetSage can answer, including: Who is using Globus to share data with my institution, and what kind of performance are they able to achieve? How many transfers has Globus supported for us? Which sites are we sharing the most data with, and how is that changing over time? How is my site using Globus to move data internally, and what kind of performance do we see for those transfers? What percentage of data transfers at my institution used Globus, and how did the overall data transfer performance compare to the Globus users?
Quarkus Hidden and Forbidden ExtensionsMax Andersen
Quarkus has a vast extension ecosystem and is known for its subsonic and subatomic feature set. Some of these features are not as well known, and some extensions are less talked about, but that does not make them less interesting - quite the opposite.
Come join this talk to see some tips and tricks for using Quarkus and some of the lesser known features, extensions and development techniques.
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxrickgrimesss22
Discover the essential features to incorporate in your Winzo clone app to boost business growth, enhance user engagement, and drive revenue. Learn how to create a compelling gaming experience that stands out in the competitive market.
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
top nidhi software solution freedownloadvrstrong314
This presentation emphasizes the importance of data security and legal compliance for Nidhi companies in India. It highlights how online Nidhi software solutions, like Vector Nidhi Software, offer advanced features tailored to these needs. Key aspects include encryption, access controls, and audit trails to ensure data security. The software complies with regulatory guidelines from the MCA and RBI and adheres to Nidhi Rules, 2014. With customizable, user-friendly interfaces and real-time features, these Nidhi software solutions enhance efficiency, support growth, and provide exceptional member services. The presentation concludes with contact information for further inquiries.
Developing Distributed High-performance Computing Capabilities of an Open Sci...Globus
COVID-19 had an unprecedented impact on scientific collaboration. The pandemic and its broad response from the scientific community has forged new relationships among public health practitioners, mathematical modelers, and scientific computing specialists, while revealing critical gaps in exploiting advanced computing systems to support urgent decision making. Informed by our team’s work in applying high-performance computing in support of public health decision makers during the COVID-19 pandemic, we present how Globus technologies are enabling the development of an open science platform for robust epidemic analysis, with the goal of collaborative, secure, distributed, on-demand, and fast time-to-solution analyses to support public health.
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfJay Das
With the advent of artificial intelligence or AI tools, project management processes are undergoing a transformative shift. By using tools like ChatGPT, and Bard organizations can empower their leaders and managers to plan, execute, and monitor projects more effectively.
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Anthony Dahanne
Les Buildpacks existent depuis plus de 10 ans ! D’abord, ils étaient utilisés pour détecter et construire une application avant de la déployer sur certains PaaS. Ensuite, nous avons pu créer des images Docker (OCI) avec leur dernière génération, les Cloud Native Buildpacks (CNCF en incubation). Sont-ils une bonne alternative au Dockerfile ? Que sont les buildpacks Paketo ? Quelles communautés les soutiennent et comment ?
Venez le découvrir lors de cette session ignite
How to Position Your Globus Data Portal for Success Ten Good PracticesGlobus
Science gateways allow science and engineering communities to access shared data, software, computing services, and instruments. Science gateways have gained a lot of traction in the last twenty years, as evidenced by projects such as the Science Gateways Community Institute (SGCI) and the Center of Excellence on Science Gateways (SGX3) in the US, The Australian Research Data Commons (ARDC) and its platforms in Australia, and the projects around Virtual Research Environments in Europe. A few mature frameworks have evolved with their different strengths and foci and have been taken up by a larger community such as the Globus Data Portal, Hubzero, Tapis, and Galaxy. However, even when gateways are built on successful frameworks, they continue to face the challenges of ongoing maintenance costs and how to meet the ever-expanding needs of the community they serve with enhanced features. It is not uncommon that gateways with compelling use cases are nonetheless unable to get past the prototype phase and become a full production service, or if they do, they don't survive more than a couple of years. While there is no guaranteed pathway to success, it seems likely that for any gateway there is a need for a strong community and/or solid funding streams to create and sustain its success. With over twenty years of examples to draw from, this presentation goes into detail for ten factors common to successful and enduring gateways that effectively serve as best practices for any new or developing gateway.
Software Engineering, Software Consulting, Tech Lead.
Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Security,
Spring Transaction, Spring MVC,
Log4j, REST/SOAP WEB-SERVICES.
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Globus
The Earth System Grid Federation (ESGF) is a global network of data servers that archives and distributes the planet’s largest collection of Earth system model output for thousands of climate and environmental scientists worldwide. Many of these petabyte-scale data archives are located in proximity to large high-performance computing (HPC) or cloud computing resources, but the primary workflow for data users consists of transferring data, and applying computations on a different system. As a part of the ESGF 2.0 US project (funded by the United States Department of Energy Office of Science), we developed pre-defined data workflows, which can be run on-demand, capable of applying many data reduction and data analysis to the large ESGF data archives, transferring only the resultant analysis (ex. visualizations, smaller data files). In this talk, we will showcase a few of these workflows, highlighting how Globus Flows can be used for petabyte-scale climate analysis.
Cyaniclab : Software Development Agency Portfolio.pdfCyanic lab
CyanicLab, an offshore custom software development company based in Sweden,India, Finland, is your go-to partner for startup development and innovative web design solutions. Our expert team specializes in crafting cutting-edge software tailored to meet the unique needs of startups and established enterprises alike. From conceptualization to execution, we offer comprehensive services including web and mobile app development, UI/UX design, and ongoing software maintenance. Ready to elevate your business? Contact CyanicLab today and let us propel your vision to success with our top-notch IT solutions.
Unleash Unlimited Potential with One-Time Purchase
BoxLang is more than just a language; it's a community. By choosing a Visionary License, you're not just investing in your success, you're actively contributing to the ongoing development and support of BoxLang.
A Comprehensive Look at Generative AI in Retail App Testing.pdfkalichargn70th171
Traditional software testing methods are being challenged in retail, where customer expectations and technological advancements continually shape the landscape. Enter generative AI—a transformative subset of artificial intelligence technologies poised to revolutionize software testing.
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTier1 app
Even though at surface level ‘java.lang.OutOfMemoryError’ appears as one single error; underlyingly there are 9 types of OutOfMemoryError. Each type of OutOfMemoryError has different causes, diagnosis approaches and solutions. This session equips you with the knowledge, tools, and techniques needed to troubleshoot and conquer OutOfMemoryError in all its forms, ensuring smoother, more efficient Java applications.
Enhancing Research Orchestration Capabilities at ORNL.pdfGlobus
Cross-facility research orchestration comes with ever-changing constraints regarding the availability and suitability of various compute and data resources. In short, a flexible data and processing fabric is needed to enable the dynamic redirection of data and compute tasks throughout the lifecycle of an experiment. In this talk, we illustrate how we easily leveraged Globus services to instrument the ACE research testbed at the Oak Ridge Leadership Computing Facility with flexible data and task orchestration capabilities.
Globus Connect Server Deep Dive - GlobusWorld 2024Globus
We explore the Globus Connect Server (GCS) architecture and experiment with advanced configuration options and use cases. This content is targeted at system administrators who are familiar with GCS and currently operate—or are planning to operate—broader deployments at their institution.
2. Hi, I’m Jim Lynch
Front-End Engineer
at Altered Image
@webWhizJim
Slides available here:
http://www.slideshare.net/JimLynch22/describes-full-of-its
WebStorm
Ambassador
Programming Tweeter
3. Who is This Talk For?
• Anyone interested in unit testing.
• AngularJS developers.
• Front-End developers.
4. Why Test?
• To prevent regression (recurring bugs).
• To catch bugs before end users see them.
• To remove fear from refactoring.
• So you don’t have to keep testing manually.
• To document what your code should do.
• To gain a sense of confidence that you
can never have without tests!
6. Artifacts
• True, but also a clean production
build (the dist/ directory)
• When the project is over, what will
you leave behind?
• “A programmer’s deliverables should
be clean code and clean tests”
- Pete Heard
9. Anatomy of a Test Suite
Test Case
Test Case
Test Suite
10. Anatomy of a Test Suite
Test Case
Assertion
Assertion
Assertion
Test Case
Test Suite
11. Anatomy of a Test Suite
Test Suite
• A collection of independent tests.
• Usually exists as it’s own file.
• Contains methods for setting
up for and tearing down unit
tests.
Test Case
Assertion
Assertion
Assertion
Test Case
Test Suite
12. Anatomy of a Test Suite
Test Case
• Tests a single “piece” of your
application independent of the
other code.
• A function that can either pass or
fail.
• Each case should test a
different “situation” from the
user’s perspective (BDD).
Test Case
Assertion
Assertion
Assertion
Test Case
Test Suite
13. Anatomy of a Test Suite
Test Case
Assertion
Assertion
Assertion
Test Case
Test Suite
Assertion
• Uses a matcher API for comparing
values
(eg toEqual)
• Tells the test case when it should
pass and when it should fail.
• If output values for SUT (system
under test) are as expected then
behavior of SUT is as expected.
17. Test Suite Anatomy for JS
Testing Frameworks
it
describeTest Suite
Test Case
Assertion expect
it
expect
expect
18. Building Your First Test Suite
• A test suite is simply a Javascript file.
• Karma will automatically consider *.spec.js
files to be test suites.
Step 1) Create an empty *.spec.js file.
19. Keep the Tests Close By
• For every .js file, make a .spec.js file right next to it.
• Test file should have exact same name
(other than the .spec part).
• Having a root level “tests” folder is an old-school
practice and not recommended.
• Gulp scripts should recognize tests throughout
entire project directory.
24. describe describe(‘MyController’, function() {
})
A name for your test suite
(can be anything, but it should
describe what you are testing!).
Building Your First Test Suite
Adding a describe.
25. describe describe(‘MyController’, function() {
})
A function that takes no
arguments. This creates the
“wrapper” around your test
cases.
Building Your First Test Suite
Adding a describe.
27. describe
describe(‘MyController’, function() {
})
Some text that describes the
purpose of this test case. Can be
anything but usually begins with
the word should.
it
Building Your First Test Suite
it(‘Should do something…’, function() {
});
Adding an it.
30. describe
describe(‘MyController’, function() {
})
it
Building Your First Test Suite
it(‘Should do something…’, function() {
});
Adding an assertion.
expect
expect(true).toEqual(true);
The expect keyword let’s the
test case know that we want to
do an assertion here.
31. describe
describe(‘MyController’, function() {
})
it
Building Your First Test Suite
it(‘Should do something…’, function() {
});
Adding an assertion.
expect
expect(true).toEqual(true);
The expect method takes one
argument, the variable whose
value you wish to check.
32. describe
describe(‘MyController’, function() {
})
it
Building Your First Test Suite
it(‘Should do something…’, function() {
});
Adding an assertion.
expect
expect(true).toEqual(true);
Depending on how you wish to
compare the two values, a
matcher method is chained
onto the end of the expect.
33. describe
describe(‘MyController’, function() {
})
it
Building Your First Test Suite
it(‘Should do something…’, function() {
});
Adding an assertion.
expect
expect(true).toEqual(true);
The matcher method takes one
argument. The expected value
for the variable being passed
into the expect method.
34. Building Your First Test Suite
You did it!
describe(‘MyController’, function() {
})
it(‘Should do something…’, function() {
});
expect(true).toEqual(true);
Ahhh, so a test suite is really just…
36. beforeEach
• Goes inside the describe
but outside of the it’s.
describe
it
expect
it
expect
beforeEach
beforeEach
• Gives you access to your
module, controllers,
services, etc. through DI.
41. Injecting a Controller
with beforeEach
describe(‘MyController’, function() {
})
it(‘Should do something…’, function() {
});
expect(true).toEqual(true);
beforeEach(module(‘YOUR_MODULE’));
var myController = $controller('MyController', {})
beforeEach(inject(function(_$controller_) {
$controller = _$controller_;
}));
42. Injecting a Controller
with beforeEach
beforeEach(inject(function(_$controller_) {
$controller = _$controller_;
}));
A method from the angular-
mocks.js file that allows you to
inject services into your unit tests.
43. Injecting a Controller
with beforeEach
beforeEach(inject(function(_$controller_) {
$controller = _$controller_;
}));
Angular knows to “unwrap”, the underscores,
find corresponding provider, and give you a
reference to the service.
Q. But what’s the deal with those
underscores on either side?
44. Injecting a Controller
with beforeEach
beforeEach(inject(function(_$controller_) {
$controller = _$controller_;
}));
Angular knows to “unwrap”, the underscores,
find corresponding provider, and give you a
reference to the service.
Suppose you didn’t use the underscores. You want to set a variable named
$controller available inside of your “it’s” equal to the function’s argument, but the
function argument must be named $controller in order to be injected properly.
Doing this is not possible in JavaScript (outer variable is overshadowed) so the
Angular team implemented the underscore notation to work around the issue.
45. Injecting a Controller
with beforeEach
beforeEach(inject(function(_$controller_) {
$controller = _$controller_;
}));
You can then use this global
reference anywhere in the test suite
to instantiate controllers.
46. Using the Injected
Controller
var myController = $controller('MyController', {})
This var has all of the properties
and methods you defined for the
specified controller.
47. Using the Injected
Controller
var myController = $controller('MyController', {})
This is the global $controller
variable that was set in the
beforeEach.
48. Using the Injected
Controller
var myController = $controller('MyController', {})
Replace this with the name
of the controller you want
to instantiate.
49. Pass in any arguments to your
controller with this object.
var myController = $controller('MyController', {})
Using the Injected
Controller
50. The Complete Suite
describe(‘MyController’, function() {
})
it(‘Should do something…’, function() {
});
expect(true).toEqual(true);
beforeEach(module(‘YOUR_MODULE’));
var myController = $controller('MyController', {})
beforeEach(inject(function(_$controller_) {
$controller = _$controller_;
}));
A good start to a nice looking test suite:
51. Okay, so how do I run
these test suites?
Q )
KarmaA )
52. Fun Facts About Karma
• Worked with non-Angular projects as well.
• A command line test runner built to be fast.
• Integrates with practically all CI tools.
• Runs tests on all browsers (even PhantomJS).
53. How Does Karma Work?
• It integrates nicely with Gulp and Grunt (gulp test)
or runs on its own (karma start).
• It’s installed from npm: npm install karma
• The karma.conf.js file allows you to configure it to
run with your desired settings.
• It automatically see *.spec.js files in your project
folder as test suites.
55. Easy Way Hard(er) Way
Use a yeoman generator to
scaffold a project that already
has karma set up for you
(such as the Gulp-Angular
yeoman generator or the
Angular 2 CLI).
Install and configure it
manually.
karma-runner.github.io
Adding Karma to Your Project
And then you’re ready to start testing!
56. Workflow
Browsersync
Chrome Dev Tools
See Your App Running
Logs / Debugging
Runs Unit Tests on File
Changes
No need to test manually
Reminds you to write
more tests
Gulp Serve Gulp Test:Auto
61. The CLI Replaces Gulp Tasks
https://cli.angular.io/
Angular 1 Angular 2
yo gulp-angular ng new / ng initNew project:
gulp serve ng serveRun locally:
gulp serve:dist ng serve —-buildRun prod build:
gulp test:auto ng test -wRun unit tests
gulp protractor ng e2eRun e2e tests
gulp build ng buildCreate prod build
62. In Angular 2 You Can
Still Think of a Unit
Test as…