I am trying to write tests using Jasmine/karma to test http get/post requests from an app we are currently building. I managed to write up a sample test, but it seems to produce disconnected Error, I have attached the test and terminal output. Really appreciate if someone could help me resolve this issue.
test.spec.ts
import "reflect-metadata";
import '/Users/Pradeepan/Documents/lawdiary/node_modules/http://ift.tt/2asjGLq';
import {
async, inject, TestBed
} from '@angular/core/testing';
import {
MockBackend,
MockConnection
} from '@angular/http/testing';
import {
HttpModule, Http, XHRBackend, Response, ResponseOptions
} from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/toPromise';
import { LawyerPage } from '/Users/Pradeepan/Documents/lawdiary/app/pages/lawyer/lawyer.component';
import { LawyerService } from '/Users/Pradeepan/Documents/lawdiary/app/shared/services/lawyer.service';
import { Lawyer } from '/Users/Pradeepan/Documents/lawdiary/app/shared/entities/Lawyer';
describe("test", function () {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpModule],
providers: [
LawyerService,
{ provide: XHRBackend, useClass: MockBackend }
]
})
.compileComponents();
});
it('can instantiate service when inject service',
inject([LawyerService], (service: LawyerService) => {
console.log("I am Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
expect(service instanceof LawyerService).toBe(true);
}));
it('can instantiate service with "new"', inject([Http], (http: Http) => {
expect(http).not.toBeNull('http should be provided');
let service = new LawyerService(http);
expect(service instanceof LawyerService).toBe(true, 'new service should be ok');
}));
it('can provide the mockBackend as XHRBackend',
inject([XHRBackend], (backend: MockBackend) => {
expect(backend).not.toBeNull('backend should be provided');
}));
});
karma.conf.js
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: http://ift.tt/1ft83uu
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'app/**/*.js',
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: http://ift.tt/1gyw6MG
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: http://ift.tt/1ft83KQ
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: http://ift.tt/1ft83KU
browsers: [],
customLaunchers: {
android: {
base: 'NS',
platform: 'android'
},
ios: {
base: 'NS',
platform: 'ios'
},
ios_simulator: {
base: 'NS',
platform: 'ios',
arguments: ['--emulator']
}
},
browserNoActivityTimeout: 100000,
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true
})
}
Terminal Output
Aucun commentaire:
Enregistrer un commentaire