angular-test

Angular Testing, dynamically change ActivatedRoute params for different test cases

孤街醉人 提交于 2019-12-12 10:39:28
问题 Component: @Component({ selector: 'app-test', templateUrl: './test.component.html' }) export class TestComponent implements OnInit { useCase: string; constructor( private route: ActivatedRoute, ) {} ngOnInit() { this.route.queryParams.subscribe(p => { if (p) { this.useCase = p.u; } }); } } Test Spec describe('TestComponent', () => { let component: TestComponent; let fixture: ComponentFixture<TestComponent>; beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ AppModule ],

Angular Jasmine - Test case gets failed in http HEAD request while on Flush

落花浮王杯 提交于 2019-12-11 19:45:28
问题 I'm trying to write a test case for the HTTP HEAD Request, it works fine without flush method. If I triggered the flush method the chrome browser gets disconnect. I don't know what needs to pass as a param to the flush method. Example: Service Method processData(id): void { const url = `http://localhost:5000/data/${id}`; this.http.head(url).subscribe(() => { console.log('Success'); // Rest of the code - TODO }, (error) => { console.log('Failed'); // Rest of the code - TODO }); } Test Case

How to tell Protractor to use hash in baseUrl globally?

拜拜、爱过 提交于 2019-12-11 17:50:04
问题 Currently, HashLocationStrategy is enabled in my Angular App, and when I run expect(browser.getCurrentUrl()).toBe(browser.baseUrl + '/login'); in my e2e spec, I receive following error: Expected 'http://localhost:49152/#/login' to be 'http://localhost:49152/login'. Is there a way to tell Protractor to use hash suffix in baseUrl globally? 回答1: You can define baseUrl in your config file Or pass parameter from command line or Jenkins so that it would be available to all specs. exports.config = {

Angular Testing Error: Can't resolve all parameters for Service:

大城市里の小女人 提交于 2019-12-10 17:48:01
问题 I'm new to testing. I have a service and a spec file that when run I get the following error: Error: Can't resolve all parameters for DashboardService: (?). error properties: Object({ ngSyntaxError: true }) The spec file looks like this: import { TestBed } from '@angular/core/testing'; import { DashboardService } from './dashboard.service'; import { ApiService } from './../api.service'; describe('The Dashboard Service', () => { beforeEach(() => { TestBed.configureTestingModule({ providers:

Submitting form with enter key in Angular unit test

会有一股神秘感。 提交于 2019-12-08 16:58:52
问题 I'm writing a test for an Angular 4 component that is a login form. The form can be submitted by clicking on the "submit" button or by hitting enter in any input fields. This behaviour is dictated by the Angular form directive. I can write a test case that validates that a button click submits the form, but I can't trigger the submit behaviour with a keypress event. Template: <form (ngSubmit)="onLoginSubmit()" #loginForm="ngForm"> <div class="form-group"> <label for="userid">User ID</label>

Error-Property value does not exist in type name string

荒凉一梦 提交于 2019-12-08 13:37:49
问题 I hope this question clarifies so many people about testing template driven forms that Angular documentation barely mentions. I have an input inside this form that I want to test. I want to test a simple DOM in Angular using Jasmine. This is a template driven form using NgForm like this: <form name="editForm" role="form" novalidate (ngSubmit)="save()" #editForm="ngForm"> <input #inputtotest type="text" class="form-control" name="nombre" id="field_nombre" [(ngModel)]="paciente.nombre" required

Ag-grid access and edit cell from Protractor e2e tests

北战南征 提交于 2019-12-08 10:19:40
问题 I'm looking to the right way to end to end test (e2e) an ag-grid angular application. protractor documentation says that you can use by.model(modelName) to sendKeys to an input field using ng-model. https://www.protractortest.org/#/api?view=ProtractorBy.prototype.model But ng-model is not an angular 2 directive I've tried for example this method but it's not working: const cellElement = element(by.model('row.name')); browser.actions().click(cellElement).perform(); //to get focus on cell

How do I turn off source maps for Angular 6 ng test?

允我心安 提交于 2019-12-03 11:17:16
问题 I am trying to turn off sourcemaps for my tests in Angular 6. I know the sourcemaps switch has been removed, e.g., ng test --sourcemaps=false . I have tried modifying my tsconfig file: { "extends": "../tsconfig.json", "compilerOptions": { ... "sourceMap": false }, as referenced by the angular.json test->configuration block: "test": { ... "options": { ... "tsConfig": "src/tsconfig.spec.json", The source maps are still being generated. 回答1: You can use CLI v6.0.8 and above --source-map=false

Angular2 unit test with @Input()

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 04:04:24
问题 I've got a component that uses the @Input() annotation on an instance variable and I'm trying to write my unit test for the openProductPage() method, but I'm a little lost at how I setup my unit test. I could make that instance variable public, but I don't think I should have to resort to that. How do I setup my Jasmine test so that a mocked product is injected (provided?) and I can test the openProductPage() method? My component: import {Component, Input} from "angular2/core"; import {Router

How do I turn off source maps for Angular 6 ng test?

一世执手 提交于 2019-12-03 01:33:34
I am trying to turn off sourcemaps for my tests in Angular 6. I know the sourcemaps switch has been removed, e.g., ng test --sourcemaps=false . I have tried modifying my tsconfig file: { "extends": "../tsconfig.json", "compilerOptions": { ... "sourceMap": false }, as referenced by the angular.json test->configuration block: "test": { ... "options": { ... "tsConfig": "src/tsconfig.spec.json", The source maps are still being generated. You can use CLI v6.0.8 and above --source-map=false CLI v6.x --sourceMap=false CLI v1.x --sourcemaps=false Angular CLI changing this param from version to version