Getting the test framework set up for Angular, setting up a products fetch stub

This commit is contained in:
Will Marshall
2013-12-06 15:24:42 +11:00
parent b806947e7b
commit 63dfa0b696
14 changed files with 123 additions and 43 deletions

View File

@@ -754,4 +754,4 @@ describe 'OrderCycle services', ->
expect(data.incoming_exchanges[0].enterprise_fees).toBeUndefined()
expect(data.outgoing_exchanges[0].enterprise_fees).toBeUndefined()
expect(data.incoming_exchanges[0].enterprise_fee_ids).toEqual [1, 2]
expect(data.outgoing_exchanges[0].enterprise_fee_ids).toEqual [3, 4]
expect(data.outgoing_exchanges[0].enterprise_fee_ids).toEqual [3, 4]

View File

@@ -0,0 +1,15 @@
describe 'Shop services', ->
$httpBackend = null
Product = null
beforeEach ->
module 'Shop'
inject ($injector, _$httpBackend_)->
Product = $injector.get("Product")
$httpBackend = _$httpBackend_
it "Fetches products from the backend", ->
$httpBackend.expectGET("/shop/products").respond([{test : "cats"}])
products = Product.all()
$httpBackend.flush()
expect(products[0].test).toEqual "cats"

View File

@@ -0,0 +1,18 @@
describe 'Shop controllers', ->
describe 'ProductsCtrl', ->
ctrl = null
scope = null
event = null
Product = null
beforeEach ->
module('Shop')
scope = {}
Product =
all: ->
'testy mctest'
inject ($controller) ->
ctrl = $controller 'ProductsCtrl', {$scope: scope, Product : Product}
it 'Fetches products from Product', ->
expect(scope.products).toEqual 'testy mctest'