Skip to content

Instantly share code, notes, and snippets.

@simonrenoult
Created June 15, 2017 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonrenoult/936dbed08c8818d66a7ef9dd4c42af4d to your computer and use it in GitHub Desktop.
Save simonrenoult/936dbed08c8818d66a7ef9dd4c42af4d to your computer and use it in GitHub Desktop.
Angularjs unit testing - factory
angular
.module('app.moduleA', ['app.moduleB'])
.factory('FactoryA', (FactoryB) ->
factory = {}
factory.sayHello = () -> FactoryB()
return factory
)
angular
.module('app.moduleB', [])
.factory('FactoryB', () ->
return () -> "hello"
)
describe "app.moduleA", ->
factory = undefined
beforeEach(module('app.moduleA'))
beforeEach(module(($provide) ->
$provide.value('FactoryB', () -> "world")
return null
))
beforeEach(() ->
inject((FactoryA) ->
factory = FactoryA
)
)
it "exists", () ->
expect(factory.sayHello()).toEqual("world")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment