Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use $httpBackend service in unit tests with apiMock #64

Open
juri33 opened this issue Dec 8, 2016 · 1 comment
Open

Use $httpBackend service in unit tests with apiMock #64

juri33 opened this issue Dec 8, 2016 · 1 comment

Comments

@juri33
Copy link

juri33 commented Dec 8, 2016

Your package is really helpful. Thank you guys.

I my old unit tests i am using $httpBackend with .whenGET mocks.

beforeEach(() => {
  inject(function ($injector, _$compile_, _$rootScope_) {
    // The injector unwraps the underscores (_) from around the parameter names when matching
    $compile = _$compile_;
    $rootScope = _$rootScope_;
    $httpBackend = $injector.get("$httpBackend");
  });

$httpBackend.whenGET("api/langs/gb.json").respond({ "COMMON.HOME": homeName });
$httpBackend.whenGET("api/langs/de.json").respond({});

$httpBackend.whenGET(/^private\/auth\?.*/).respond({});

directiveElem = getCompiledElement();
});

Now i have included apiMock and my unit tests doesn't work any more.

it("should be defined and contiain first list item for home.", function () {

$httpBackend.flush();
expect(directiveElem).toBeDefined();

let olElement = directiveElem.find("ol");
expect(olElement).toBeDefined();

let homeElement = directiveElem.find("li");
expect(homeElement.html()).toContain(homeName);
});

I have tried

  apiMockProvider.config({
    disable: true
  });

but it didn't help.

@seriema
Copy link
Owner

seriema commented Dec 26, 2016

Hmm odd, I use $httpBackend in our unit tests. The disable flag would still keep apiMock registered, just not run any logic. Still odd that it's breaking for you. What error are you seeing @juri33?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants