Skip to content Skip to sidebar Skip to footer

Writing Karma + Mocha Tests With Both Dependency Injection And `done`?

What's the most elegant way to write Karma unit tests in mocha that both have dependency injection and done? Dependency injection: describe('cows', function(){ it('farts a lot',

Solution 1:

You can nested function inject into test function

it("should nested inject function into test function", function(done) {
    inject(function($timeout) {

      $timeout(function() {
        expect(true).toBeTruthy();
        done();
      }, 10);

      $timeout.flush(10);

    });    
  });

inject is global function defined in ngMock module and can be used anywhere in the test.

Post a Comment for "Writing Karma + Mocha Tests With Both Dependency Injection And `done`?"