question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Promises not resolving with Jasmine/Karma test

See original GitHub issue

Promises resolve fine when run normally, but don’t resolve at all when run as part of a karma/jasmine test. .then calls (even in the controller) don’t run.

Minimal example demonstrating the problem

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
katowulfcommented, Jun 9, 2014

Since Angular uses mocks, pretty much everything has to be flushed by hand. AngularFire depends on $timeout internally, so that has to get flushed any time an angularFire op is expected. Most of the AngularFire tests do something like this:

var $timeout;
beforeEach(inject(function(_$timeout_) {
     $timeout = _$timeout_;
});

it('should be flushed', function() {
     var ref = new Firebase(URL);
     var data = $firebase(ref);
     $timeout.flush();
     var spy = jasmine.createSpy('test flush');
     ref.$add({foo: 'bar'}, spy);
     $timeout.flush();
     // if you are using MockFirebase
     // Firebase.flush();
    expect(spy.callCount).toBe(1);     
});

That may help a bit.

0reactions
SomeKittenscommented, Jun 18, 2014

Thanks guys. This helped my understanding a lot. Looks like I’ve got some hackarounds to code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jasmine test a promise.then function - Stack Overflow
One approach I've found useful when testing is mocking dependencies. ... promise deferred.resolve(123); // Note that the 'then' function does not get called ......
Read more >
Unit Testing Async Calls and Promises with Jasmine - Medium
Promises can often be puzzling to test due to their asynchronous nature. After looking at Jasmine documentation, you may be thinking there's got...
Read more >
Promises not resolving with Jasmine/Karma test #318 - GitHub
The issue is getting a callback when the Firebase data returns. The promise handlers need to be flushed manually under test and you...
Read more >
Angular Unit Testing Promise All | Karma | Jasmine - YouTube
karma #angular #unit testingHow to unit test promise.all in Angular. Unit testing Asynchronous Call in Angular.In this video, you'll learn ...
Read more >
Frequently Asked Questions - Jasmine Documentation
How do I test async behavior that I don't have a promise or callback for, like a UI component that renders something after...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found