From 68286279f76a5c4d181d4d8133dd6b3f73a34727 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Sat, 19 Dec 2015 13:36:05 +0200 Subject: [PATCH] refactor tests --- lib/components/ApiInfo/api-info.spec.js | 33 ++++++++++++----------- lib/components/Method/method.spec.js | 35 ++++++++++++++----------- lib/components/Redoc/redoc.spec.js | 2 +- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/lib/components/ApiInfo/api-info.spec.js b/lib/components/ApiInfo/api-info.spec.js index 277a817f..e51f80d5 100644 --- a/lib/components/ApiInfo/api-info.spec.js +++ b/lib/components/ApiInfo/api-info.spec.js @@ -17,6 +17,8 @@ import SchemaManager from 'lib/utils/SchemaManager'; describe('ApiInfo Component', () => { let builder; + let component; + let fixture; beforeEachProviders(() => [ provide(SchemaManager, {useValue: new SchemaManager()}) ]); @@ -24,27 +26,26 @@ describe('ApiInfo Component', () => { builder = tcb; return schemaMgr.load('/tests/schemas/api-info-test.json').then(() => null, (err) => { throw err; }); })); - - - it('shold init component data', (done) => { - builder.createAsync(TestApp).then(fixture => { - let apiInfoComponent = getChildDebugElement(fixture.debugElement, 'api-info').componentInstance; - expect(apiInfoComponent).not.toBeNull(); + beforeEach((done) => { + builder.createAsync(TestApp).then(_fixture => { + fixture = _fixture; + component = getChildDebugElement(fixture.debugElement, 'api-info').componentInstance; fixture.detectChanges(); - expect(apiInfoComponent.data).not.toBeNull(); - apiInfoComponent.data.title.should.be.equal('Swagger Petstore'); done(); }, err => done.fail(err)); }); - it('shold render api name and version', (done) => { - builder.createAsync(TestApp).then(fixture => { - let nativeElement = getChildDebugElement(fixture.debugElement, 'api-info').nativeElement; - let headerElement = nativeElement.querySelector('h1'); - fixture.detectChanges(); - expect(headerElement).toHaveText('Swagger Petstore (1.0.0)'); - done(); - }, err => done.fail(err)); + + it('shold init component data', () => { + expect(component).not.toBeNull(); + expect(component.data).not.toBeNull(); + component.data.title.should.be.equal('Swagger Petstore'); + }); + + it('shold render api name and version', () => { + let nativeElement = getChildDebugElement(fixture.debugElement, 'api-info').nativeElement; + let headerElement = nativeElement.querySelector('h1'); + expect(headerElement).toHaveText('Swagger Petstore (1.0.0)'); }); }); diff --git a/lib/components/Method/method.spec.js b/lib/components/Method/method.spec.js index 764e19ac..13d9216b 100644 --- a/lib/components/Method/method.spec.js +++ b/lib/components/Method/method.spec.js @@ -15,8 +15,9 @@ import Method from 'lib/components/Method/method'; import SchemaManager from 'lib/utils/SchemaManager'; -describe('jjj Component', () => { +describe('Method Component', () => { let builder; + let component; beforeEachProviders(() => [ provide(SchemaManager, {useValue: new SchemaManager()}) ]); @@ -24,31 +25,33 @@ describe('jjj Component', () => { builder = tcb; return schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => null, (err) => { throw err; }); })); - - - it('should init component', (done) => { + beforeEach((done) => { builder.createAsync(TestApp).then(fixture => { - let component = getChildDebugElement(fixture.debugElement, 'method').componentInstance; - expect(component).not.toBeNull(); + component = getChildDebugElement(fixture.debugElement, 'method').componentInstance; + fixture.detectChanges(); done(); }, err => done.fail(err)); }); - it('should init basic component data', (done) => { - builder.createAsync(TestApp).then(fixture => { - let component = getChildDebugElement(fixture.debugElement, 'method').componentInstance; - fixture.detectChanges(); - component.data.apiUrl.should.be.equal('http://petstore.swagger.io/v2'); - component.data.httpMethod.should.be.equal('put'); - component.data.path.should.be.equal('/user/{username}'); - done(); - }, err => done.fail(err)); + it('should init component', () => { + expect(component).not.toBeNull(); + }); + + it('should init basic component data', () => { + component.data.apiUrl.should.be.equal('http://petstore.swagger.io/v2'); + component.data.httpMethod.should.be.equal('put'); + component.data.path.should.be.equal('/user/{username}'); + }); + + + it('should main tag', () => { + component.data.methodInfo.tags.should.be.empty; }); }); -/** Test component that contains an Method. */ +/** Test component that contains a Method. */ @Component({selector: 'test-app'}) @View({ directives: [Method], diff --git a/lib/components/Redoc/redoc.spec.js b/lib/components/Redoc/redoc.spec.js index c028a34f..3185a7bc 100644 --- a/lib/components/Redoc/redoc.spec.js +++ b/lib/components/Redoc/redoc.spec.js @@ -36,7 +36,7 @@ describe('Redoc Component', () => { }); -/** Test component that contains an Redoc. */ +/** Test component that contains a Redoc. */ @Component({selector: 'test-app'}) @View({ directives: [Redoc],