3

I am trying to perform an asynchronous unit test:

 it('Async thing', function (done) {
      scope.$on('async-stuff-happened', function (e) {
         console.log(e);
         done();
         expect(e.stuff).toEqual("stuff");
     });
     scope.ayncStuff();
 });

I can see in the console the line console.log(e) executed, but the test result is :

SPEC HAS NO EXPECTATIONS Async thing

What am I missing?

vtortola
  • 34,709
  • 29
  • 161
  • 263

1 Answers1

6

Just move the done() call down after the assert statement:

it('Async thing', function (done) {
  scope.$on('async-stuff-happened', function (e) {
    console.log(e);
    expect(e.stuff).toEqual("stuff");
    done();
  });
  scope.ayncStuff();
});
runTarm
  • 11,537
  • 1
  • 37
  • 37