Created
June 15, 2017 08:27
-
-
Save simonrenoult/936dbed08c8818d66a7ef9dd4c42af4d to your computer and use it in GitHub Desktop.
Angularjs unit testing - factory
This file contains 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('app.moduleA', ['app.moduleB']) | |
.factory('FactoryA', (FactoryB) -> | |
factory = {} | |
factory.sayHello = () -> FactoryB() | |
return factory | |
) | |
angular | |
.module('app.moduleB', []) | |
.factory('FactoryB', () -> | |
return () -> "hello" | |
) |
This file contains 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 "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