SlideShare a Scribd company logo
1 of 43
Download to read offline
Intro to Testing an
EmberJS Application
Ben Limmer
EmberJS Denver Meetup
7/29/2015
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
slides are available on
slideshare / ember.party
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
why do we test?
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
write better code
less need for
manual qa
confidence when
refactoring
living documentation
confidence when
upgrading
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
3 levels of testing
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
Unit
Integration
Acceptance
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
Unit
Integration
Acceptance
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
Unit
Integration
Acceptance
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
ember unit tests
• actions
• computed properties with sophisticated logic
• mixins
• util functions
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
ember unit tests
function
input
expected
output
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
Unit
Integration
Acceptance
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
ember integration tests
• components
• actions sent from components
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
ember integration tests
component
interaction
expected
state
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
ember integration tests
component
interaction
expected
action
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
Unit
Integration
Acceptance
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
ember acceptance tests
• rendered routes
• transitions between routes
• communicating with the (fake) server
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
ember acceptance tests
application
interaction
expected
state
application
interaction
expected
state
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
qunit vs. mocha
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
qunit vs. mocha (chai)
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
qunit
• 1st class support
• syntax is not as ‘fluent’
qunit
test('it renders', function(assert) {
this.render(hbs`{{foo-bar}}`);
assert.equal(this.$('button').text(), 'Click Me');
});
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
mocha
• Good support, but not 1st class
• Highly fluent syntax
mocha / chai
it('has a button with text', function() {
this.render(hbs`{{foo-bar}}`);
expect(this.$('button').text()).to.equal('Click Me');
});
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
demo
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
don’t panic -
source is on github
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
what do we test?
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
Unit
Integration
Acceptance
mixins/authenticated-route.js
export default Ember.Mixin.create({
session: Ember.inject.service(),
signInRoute: 'sign-in',
beforeModel: function() {
if (this.get('session.isLoggedIn')) {
return;
} else {
this.replaceWith(this.get('signInRoute'));
}
}
});
mixins/authenticated-route-test.js
describe('beforeModel', function() {
const signInRoute = 'sign-in';
let subject, replaceWithStub, session;
beforeEach(function() {
const AuthenticatedRouteObject = Ember.Route.extend(
AuthenticatedRouteMixin);
replaceWithStub = sinon.stub();
session = Ember.Object.create();
subject = AuthenticatedRouteObject.create({
session: session,
signInRoute: signInRoute,
replaceWith: replaceWithStub
});
});
it('does nothing if logged in');
it('transitions to the sign in route if not logged in');
});
it('does nothing if logged in', function() {
session.set(‘isLoggedIn’, true);
subject.beforeModel();
expect(replaceWithStub.called).to.be.false;
});
it('transitions to the sign in route if not logged in',
function() {
session.set('isLoggedIn', false);
subject.beforeModel();
expect(replaceWithStub.withArgs(signInRoute).calledOnce).to.be.true;
});
mixins/authenticated-route-test.js
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
Unit
Integration
Acceptance
components/sign-in-
form.hbs
1 <h4 id='sign-in-greeting'>
2 Click the Button Below to Login as {{user.email}}
3 </h4>
4 <button id='sign-in-cta' class='button' {{action 'signIn'}}>
5 Sign In
6 </button>
components/sign-in-form.js
1 export default Ember.Component.extend({
2 actions: {
3 signIn: function() {
4 this.sendAction(‘signIn', this.get('user'));
5 }
6 }
7 });
components/sign-in-form-
test.js
it('shows the user's email address', function() {
this.set('user', Ember.Object.create({
email: 'foo@bar.com'
}));
this.render(hbs`{{sign-in-form user=user}}`);
expect(this.$('#sign-in-greeting').text()).to.contain('foo@bar.com');
});
it('has a button to login', function() {
this.render(hbs`{{sign-in-form}}`);
expect(this.$('button#sign-in-cta').length).to.equal(1);
});
components/sign-in-form-
test.js
it('sends the login action with the user when clicking the button',
function(done) {
const user = Ember.Object.create({
email: 'foo@bar.com'
});
this.set('user', user);
this.on('signIn', function(actionUser) {
expect(actionUser).to.equal(user);
done();
});
this.render(hbs`{{sign-in-form user=user signIn='signIn'}}`);
this.$('button#sign-in-cta').click();
});
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
Unit
Integration
Acceptance
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
acceptance-test/sign-in-
test.js
describe('success', function() {
beforeEach(function() {
server.create('user', {
email: 'hello@benlimmer.com',
password: 'guest'
});
});
it('transitions to the dashboard on successful login');
it('shows a flash message on successful login');
});
acceptance-test/sign-in-
test.js
it('transitions to the dashboard on successful login', function()
{
visit('/sign-in');
click('button#sign-in-cta');
andThen(function() {
expect(currentPath()).to.equal('dashboard');
});
});
it('shows a flash message on successful login', function() {
visit('/sign-in');
click('button#sign-in-cta');
andThen(function() {
expect(find('.alert-box.success').length).to.equal(1);
});
});
acceptance-test/sign-in-
test.js
describe('failure', function() {
beforeEach(function() {
// API will return 400
server.create('user', {
email: 'notBen@gmail.com',
password: 'guest'
});
});
it('does not transition to the dashboard on failure');
it('shows a danger flash message on login failure');
});
acceptance-test/sign-in-
test.js
it('does not transition to the dashboard on failure', function() {
visit('/sign-in');
click('button#sign-in-cta');
andThen(function() {
expect(currentPath()).to.equal('sign-in');
});
});
it('shows a danger flash message on login failure', function() {
visit('/sign-in');
click('button#sign-in-cta');
andThen(function() {
expect(find('.alert-box.danger').length).to.equal(1);
});
});
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
thank you!
blimmer
l1m5
hello@benlimmer.com
ember.party
Ben LimmerEmberJS Meetup - 7/29/2015 ember.party
demo project code
• https://github.com/blimmer/emberjs-denver-
testing-talk

More Related Content

What's hot

Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and Node
Josh Mock
 
Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}
.toster
 

What's hot (20)

Selenide alternative in Python - Introducing Selene [SeleniumCamp 2016]
Selenide alternative in Python - Introducing Selene [SeleniumCamp 2016]Selenide alternative in Python - Introducing Selene [SeleniumCamp 2016]
Selenide alternative in Python - Introducing Selene [SeleniumCamp 2016]
 
Unit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsUnit Testing JavaScript Applications
Unit Testing JavaScript Applications
 
AngularJS Unit Testing
AngularJS Unit TestingAngularJS Unit Testing
AngularJS Unit Testing
 
Promise pattern
Promise patternPromise pattern
Promise pattern
 
You do not need automation engineer - Sqa Days - 2015 - EN
You do not need automation engineer  - Sqa Days - 2015 - ENYou do not need automation engineer  - Sqa Days - 2015 - EN
You do not need automation engineer - Sqa Days - 2015 - EN
 
Javascript Promises/Q Library
Javascript Promises/Q LibraryJavascript Promises/Q Library
Javascript Promises/Q Library
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and Node
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Angular JS Unit Testing - Overview
Angular JS Unit Testing - OverviewAngular JS Unit Testing - Overview
Angular JS Unit Testing - Overview
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJS
 
Ember and containers
Ember and containersEmber and containers
Ember and containers
 
Intro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJSIntro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJS
 
Test-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS ApplicationsTest-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS Applications
 
Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}
 
AngularJS Unit Testing w/Karma and Jasmine
AngularJS Unit Testing w/Karma and JasmineAngularJS Unit Testing w/Karma and Jasmine
AngularJS Unit Testing w/Karma and Jasmine
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introductionAngularjs - Unit testing introduction
Angularjs - Unit testing introduction
 
Intro to testing Javascript with jasmine
Intro to testing Javascript with jasmineIntro to testing Javascript with jasmine
Intro to testing Javascript with jasmine
 
Unit testing with mocha
Unit testing with mochaUnit testing with mocha
Unit testing with mocha
 
AngularJS Unit Test
AngularJS Unit TestAngularJS Unit Test
AngularJS Unit Test
 
Callbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptCallbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascript
 

Similar to Automated Testing in EmberJS

Emberjs building-ambitious-web-applications
Emberjs building-ambitious-web-applicationsEmberjs building-ambitious-web-applications
Emberjs building-ambitious-web-applications
ColdFusionConference
 
Visual Testing: Turbo-Charge Your Functional Tests with Visual Powers in Just...
Visual Testing: Turbo-Charge Your Functional Tests with Visual Powers in Just...Visual Testing: Turbo-Charge Your Functional Tests with Visual Powers in Just...
Visual Testing: Turbo-Charge Your Functional Tests with Visual Powers in Just...
Applitools
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
Justin Cataldo
 

Similar to Automated Testing in EmberJS (20)

Emberjs building-ambitious-web-applications
Emberjs building-ambitious-web-applicationsEmberjs building-ambitious-web-applications
Emberjs building-ambitious-web-applications
 
jQuery Bay Area Conference 2010
jQuery Bay Area Conference 2010jQuery Bay Area Conference 2010
jQuery Bay Area Conference 2010
 
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 -  Fullstack end-to-end Test Automation with node.jsForwardJS 2017 -  Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
 
End-to-End Testing with Cypress
End-to-End Testing with CypressEnd-to-End Testing with Cypress
End-to-End Testing with Cypress
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
 
Getting the Most Out of jQuery Widgets
Getting the Most Out of jQuery WidgetsGetting the Most Out of jQuery Widgets
Getting the Most Out of jQuery Widgets
 
Attribute actions
Attribute actionsAttribute actions
Attribute actions
 
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST Services
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST ServicesEWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST Services
EWD 3 Training Course Part 43: Using JSON Web Tokens with QEWD REST Services
 
Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JSUnit-testing and E2E testing in JS
Unit-testing and E2E testing in JS
 
Angular 2 and Wijmo 5 - GrapeCity Echo 2016 Tokyo
Angular 2 and Wijmo 5 - GrapeCity Echo 2016 TokyoAngular 2 and Wijmo 5 - GrapeCity Echo 2016 Tokyo
Angular 2 and Wijmo 5 - GrapeCity Echo 2016 Tokyo
 
Reactive Java Microservices with Spring Boot and JHipster - Spring I/O 2022
Reactive Java Microservices with Spring Boot and JHipster - Spring I/O 2022Reactive Java Microservices with Spring Boot and JHipster - Spring I/O 2022
Reactive Java Microservices with Spring Boot and JHipster - Spring I/O 2022
 
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
 
Visual Testing: Turbo-Charge Your Functional Tests with Visual Powers in Just...
Visual Testing: Turbo-Charge Your Functional Tests with Visual Powers in Just...Visual Testing: Turbo-Charge Your Functional Tests with Visual Powers in Just...
Visual Testing: Turbo-Charge Your Functional Tests with Visual Powers in Just...
 
Angular Unit Testing from the Trenches
Angular Unit Testing from the TrenchesAngular Unit Testing from the Trenches
Angular Unit Testing from the Trenches
 
Angular Unit Testing NDC Minn 2018
Angular Unit Testing NDC Minn 2018Angular Unit Testing NDC Minn 2018
Angular Unit Testing NDC Minn 2018
 
Painless Javascript Unit Testing
Painless Javascript Unit TestingPainless Javascript Unit Testing
Painless Javascript Unit Testing
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
 
How I started to love design patterns
How I started to love design patternsHow I started to love design patterns
How I started to love design patterns
 
Обзор автоматизации тестирования на JavaScript
Обзор автоматизации тестирования на JavaScriptОбзор автоматизации тестирования на JavaScript
Обзор автоматизации тестирования на JavaScript
 

More from Ben Limmer

More from Ben Limmer (8)

Tips & Tricks for Being a Successful Tech Lead
Tips & Tricks for Being a Successful Tech LeadTips & Tricks for Being a Successful Tech Lead
Tips & Tricks for Being a Successful Tech Lead
 
1-Up Your Git Skills
1-Up Your Git Skills1-Up Your Git Skills
1-Up Your Git Skills
 
Maximize your output (sans productivity shame)
Maximize your output (sans productivity shame)Maximize your output (sans productivity shame)
Maximize your output (sans productivity shame)
 
[OLD] Understanding Github PR Merge Options (1up-ing your git skills part 2)
[OLD] Understanding Github PR Merge Options (1up-ing your git skills part 2)[OLD] Understanding Github PR Merge Options (1up-ing your git skills part 2)
[OLD] Understanding Github PR Merge Options (1up-ing your git skills part 2)
 
Upgrading Ember.js Apps
Upgrading Ember.js AppsUpgrading Ember.js Apps
Upgrading Ember.js Apps
 
Fun with Ember 2.x Features
Fun with Ember 2.x FeaturesFun with Ember 2.x Features
Fun with Ember 2.x Features
 
Building Realtime Apps with Ember.js and WebSockets
Building Realtime Apps with Ember.js and WebSocketsBuilding Realtime Apps with Ember.js and WebSockets
Building Realtime Apps with Ember.js and WebSockets
 
Building a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profitBuilding a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profit
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

Automated Testing in EmberJS