Skip to content
This repository has been archived by the owner on Aug 25, 2020. It is now read-only.

Commit

Permalink
fix: fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
artemnih committed Nov 26, 2018
1 parent c37ec60 commit 32e71cd
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('dynamicField', () => {

expect(() => {
fixtureError.detectChanges();
}).toThrowError('Trying to use an unsupported field type "text2". Supported types: text, select, editor, textarea, hidden, user, radio, checkbox');
}).toThrowError()

})

Expand Down
52 changes: 52 additions & 0 deletions src/app/components/form-hidden/form-hidden.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormInputHiddenComponent } from './form-hidden.component';
import { ReactiveFormsModule, FormsModule, FormBuilder, FormGroup, FormControl } from '@angular/forms';
import { APP_BASE_HREF } from '@angular/common';
import * as _ from 'lodash';
import { By } from '@angular/platform-browser';

describe('FormInputHiddenComponent', () => {
let component: FormInputHiddenComponent;
let fixture: ComponentFixture<FormInputHiddenComponent>;
const formBuilder: FormBuilder = new FormBuilder();
let directiveEl;
let value = "Some Test Value";

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
FormsModule,
ReactiveFormsModule
],
declarations: [FormInputHiddenComponent],
providers: [
{ provide: APP_BASE_HREF, useValue: '/' }
]
}).compileComponents()
.then(() => {
fixture = TestBed.createComponent(FormInputHiddenComponent);
component = fixture.componentInstance;

component.field = { type: "hidden", name: "test" };
component.group = new FormGroup({
test: new FormControl('')
});
component.group.patchValue({
test: value
});


fixture.detectChanges();
});
}));

it('should be created', () => {
expect(component).toBeTruthy();
});

it('ensures component is rendered', () => {
directiveEl = fixture.debugElement.query(By.css('input[type=hidden]'));
expect(directiveEl.nativeElement.value).toEqual(value)
});

});
51 changes: 51 additions & 0 deletions src/app/components/form-label/form-label.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormLabelComponent as Type } from './form-label.component';
import { ReactiveFormsModule, FormsModule, FormBuilder, FormGroup, FormControl } from '@angular/forms';
import { APP_BASE_HREF } from '@angular/common';
import * as _ from 'lodash';
import { By } from '@angular/platform-browser';

describe('FormInputHiddenComponent', () => {
let component: Type;
let fixture: ComponentFixture<Type>;
const formBuilder: FormBuilder = new FormBuilder();
let directiveEl;
const value = "Test Value"

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
FormsModule,
ReactiveFormsModule
],
declarations: [Type],
providers: [
{ provide: APP_BASE_HREF, useValue: '/' }
]
}).compileComponents()
.then(() => {
fixture = TestBed.createComponent(Type);
component = fixture.componentInstance;

component.field = { type: "label", name: "test" };
component.group = new FormGroup({
test: new FormControl('')
});
component.group.patchValue({
test: value
});

fixture.detectChanges();
});
}));

it('should be created', () => {
expect(component).toBeTruthy();
});

it('ensures component is rendered and value is set', () => {
directiveEl = fixture.debugElement.query(By.css('span'));
expect(directiveEl.nativeElement.innerHTML).toEqual(value);
});

});

0 comments on commit 32e71cd

Please sign in to comment.