0

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();

    });

});

});

1 Answer 1

1

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: []

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply, managed to implement you code but now i seem to get this error PhantomJS 2.1.1 (Mac OS X 0.0.0) Service: TracksServices should get customer details FAILED TypeError: undefined is not a constructor (near '....map(function (res) { re...') be great if you had any ideas, new to all this unit testing. thanks
I updated my answer, now resolved the issue. you were a big help, do you know any angular2 unit testing tutorials which are up to date..thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.