как написать тесты единства для метода регистрации класса AuthService
мой код Класс AuthService:
@Injectable()
export class AuthService {
constructor(private router: Router, private http: Http) {
// ...
}
registration(newUser) {
const headers = new Headers({ 'Content-Type': 'application/json' });
const options = new RequestOptions({ headers: headers });
return this.http.post('/register', JSON.stringify(newUser), options)
.map((response: Response) => response.json())
.catch(this.handleError);
}
private handleError(error: Response) {
console.error(error);
return Observable.throw(error.json().error || 'Server error');
}
}
Как запустить файл auth.service.spec.ts?
код скрипта auth.service.spec.ts
describe('AuthService', () => {
let component: AppComponent;
let fixture: ComponentFixture<AppComponent>;
let serviceTest: AuthService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
declarations: [
AppComponent
],
providers: [AuthService]
});
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
fixture.detectChanges();
serviceTest = TestBed.get(AuthService);
});
afterEach(() => {
});
it('should create the app', async(() => {
expect(true).toBe(true);
}));
it('should be created', inject([AuthService], (service: AuthService) => {
expect(service).toBeTruthy();
}));
});
Как проверить метод регистрации?
Команда:
ng test --port 4200
вызывает ошибки:
ERROR in d:/name_project/node_modules/selenium-webdriver/net/portprober.js
Module not found: Error: Can't resolve 'child_process' in 'd:\name_projectnode_modules\selenium-webdriver\net'
@ d:/name_project/node_modules/selenium-webdriver/net/portprober.js 22:15-39
@ d:/name_project/node_modules/selenium-webdriver/chrome.js
@ d:/name_project/node_modules/selenium-webdriver/testing/index.js
@ ./auth.service.spec.ts
@ .. \.spec\.ts$
@ ../test.ts
ERROR in d:/name_project/node_modules/fs.realpath/index.js
Module not found: Error: Can't resolve 'fs' in 'd:\name_projectnode_modules\fs.realpath'
@ d:/name_project/node_modules/fs.realpath/index.js 8:9-22
@ d:/name_project/node_modules/glob/glob.js
@ d:/name_project/node_modules/rimraf/rimraf.js
@ d:/name_project/node_modules/selenium-webdriver/io/index.js
@ d:/name_project/node_modules/selenium-webdriver/chrome.js
@ d:/name_project/node_modules/selenium-webdriver/testing/index.js
@ ./auth.service.spec.ts
@ .. \.spec\.ts$
@ ../test.ts
как исправить вышеперечисленные ошибки?
Я сделал куманду:
npm i selenium-webdriver --save-dev
но все равно выдает те же ошибки