user3355603
user3355603

Reputation: 1171

Angular2 rc.6 Karma Testing

Im new to the whole TTD with karma and jasmin, Im trying to run a test on my service which pull data from my DB, but I keep getting errors saying that ReferenceError: Can't find variable: beforeEachProviders in karma-test-shim.js here is my test below..

import { TracksServices } from './tracks.services.ts';

describe('Service: TracksServices', () => {

let service;
//setup
beforeEach(() => TestBed.configureTestingModule({
    imports: [ TracksModule, HttpModule ],
    providers: [
      TracksServices
    ],
}));

it('get 4 featured images', done => {

    service.featured(1, 4).subscribe(x => { 

      expect(x).toContain(track);
      expect(x.length).toEqual(4);
      done();

    });

});

});

Upvotes: 0

Views: 207

Answers (1)

Evgeniy Bokvkun
Evgeniy Bokvkun

Reputation: 11

testing API in RC6 littel bit chaged.

for example changes in angular2-webpack-starter.

import { inject, TestBed } from '@angular/core/testing';

// Load the implementations that should be tested
import { App } from './app.component';
import { AppState } from './app.service';

describe('App', () => {
  // provide our implementations or mocks to the dependency injector
  beforeEach(() => TestBed.configureTestingModule({
    providers: [
      AppState,
      App
    ]
  }));

  it('should have a url', inject([ App ], (app: App) => {
    expect(app.url).toEqual('https://twitter.com/AngularClass');
  }));

});

beforeEachProvider is removed and now using TestBed.configureTestingModule() where u should set provides: []

Upvotes: 1

Related Questions