1

Let's say I have a module -moduleX, that exposes a service (called serviceX). I have another module - moduleY, itself exposing a service called serviceY that uses serviceX.

How can I test moduleY by injecting a mocked serviceX ? NgMock does not appear to let you do that.

1 Answer 1

2

So far the best I could find is to do this:

describe "a test" ,->
  beforeEach () ->
    mockModule = angular.module "mockModule",[]
    mockModule.factory "serviceY", [()->
        return "your mocked module" 
    ]
    angular.mock.module 'moduleX', "mockModule"

then whenever you inject serviceY, the new service will be used (appearently services with the same name override eachother so that the last one added wins)

Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I've been looking for. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.