Last active
October 20, 2015 01:23
-
-
Save jbasinger/877d3608d4dd37fa1b0b to your computer and use it in GitHub Desktop.
Karma config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| files: [ | |
| '../lib/ionic/js/ionic.bundle.js', | |
| '../lib/angular-mocks/angular-mocks.js', | |
| '../js/**.js', | |
| './**.spec.js' | |
| ], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Pizza(slices){ | |
| this.slices = slices || 8; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| angular.module('starter.services', []) | |
| .factory('Pizza', function($http){ | |
| return { | |
| orderPizza: function(pizza){ | |
| return $http.post('/order',pizza); | |
| } | |
| }; | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe('Pizza Service', function(){ | |
| var pizzaService; | |
| var $httpBackend; | |
| var orderHandler; | |
| beforeEach(function(){ | |
| module('starter.services'); | |
| inject(function($injector){ | |
| pizzaService = $injector.get('Pizza'); | |
| $httpBackend = $injector.get('$httpBackend'); | |
| orderHandler = $httpBackend.whenPOST('/order').respond(200,true); | |
| }); | |
| }); | |
| it('should let me order pizza', function(){ | |
| expect(pizzaService.orderPizza).toBeDefined(); | |
| }); | |
| it('should return when I order pizza', function(){ | |
| $httpBackend.expectPOST('/order'); | |
| var pizzaPromise = pizzaService.orderPizza(new Pizza()); | |
| var orderComplete = false; | |
| pizzaPromise.then(function(data){ | |
| orderComplete = true; | |
| }); | |
| $httpBackend.flush(); | |
| expect(orderComplete == true); | |
| }); | |
| it('should handle errors', function(){ | |
| $httpBackend.expectPOST('/order'); | |
| orderHandler.respond(500); | |
| var pizzaPromise = pizzaService.orderPizza(new Pizza()); | |
| var gotError =false; | |
| pizzaPromise.catch(function(){ | |
| gotError = true; | |
| }); | |
| $httpBackend.flush(); | |
| expect(gotError == true); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe('Pizza', function(){ | |
| it("should default to 8 slices", function(){ | |
| var p = new Pizza(); | |
| expect(p.slices == 8); | |
| }); | |
| it("should let me override the number of slices", function(){ | |
| var p = new Pizza(12); | |
| expect(p.slices == 12); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment