From 918a4e80b0608ec5d8726ec12f62ffbdb26fc3bf Mon Sep 17 00:00:00 2001 From: artemsky Date: Wed, 9 May 2018 21:13:31 +0300 Subject: [PATCH] fix tests --- angular.json | 4 ++-- example/app/app.component.spec.ts | 38 +++++++++++-------------------- gulpfile.js | 2 +- package.json | 2 +- 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/angular.json b/angular.json index b061824..67cbd70 100644 --- a/angular.json +++ b/angular.json @@ -76,8 +76,8 @@ "example/styles.scss" ], "assets": [ - "example/assets", - "example/favicon.ico" + { "glob": "**/*", "input": "example/assets/", "output": "/assets/" }, + { "glob": "example/favicon.ico", "input": "/src", "output": "/" } ] } }, diff --git a/example/app/app.component.spec.ts b/example/app/app.component.spec.ts index ee860d5..1f3ed06 100644 --- a/example/app/app.component.spec.ts +++ b/example/app/app.component.spec.ts @@ -1,13 +1,16 @@ /* tslint:disable:no-unused-variable */ import { FormsModule } from '@angular/forms'; -import { TestBed, async } from '@angular/core/testing'; +import { TestBed, ComponentFixture, async } from '@angular/core/testing'; import { AppComponent } from './app.component'; import {SnotifyModule, SnotifyService, ToastDefaults} from 'ng-snotify'; import {SnotifyPosition} from '../../src/snotify/enums/SnotifyPosition.enum'; describe('NgSnotify Testing', () => { - beforeEach(() => { + let component: AppComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ FormsModule, SnotifyModule ], declarations: [ @@ -17,27 +20,27 @@ describe('NgSnotify Testing', () => { { provide: 'SnotifyToastConfig', useValue: ToastDefaults}, SnotifyService ] - }); + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(AppComponent); + component = fixture.componentInstance; + fixture.detectChanges(); }); it('should create the app', (done) => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.debugElement.componentInstance; - expect(app).toBeTruthy(); + expect(component).toBeTruthy(); done(); }); it(`should render title in a h1 tag 'Ng-Snotify'`, (done) => { - const fixture = TestBed.createComponent(AppComponent); - fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; expect(compiled.querySelector('.brand h1').textContent).toContain('Ng-Snotify'); done(); }); it(`should init basic options`, (done) => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.debugElement.componentInstance; const service: SnotifyService = fixture.debugElement.injector.get(SnotifyService); fixture.detectChanges(); expect(service.config).toEqual(jasmine.objectContaining(ToastDefaults)); @@ -45,8 +48,6 @@ describe('NgSnotify Testing', () => { }); it('should create success toast with body', (done) => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.debugElement.componentInstance; const service: SnotifyService = fixture.debugElement.injector.get(SnotifyService); fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; @@ -57,8 +58,6 @@ describe('NgSnotify Testing', () => { }); it('should create simple toast with body and title', (done) => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.debugElement.componentInstance; const service: SnotifyService = fixture.debugElement.injector.get(SnotifyService); fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; @@ -71,9 +70,6 @@ describe('NgSnotify Testing', () => { it('should execute confirm button action', (done) => { let result = null; - - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.debugElement.componentInstance; const service: SnotifyService = fixture.debugElement.injector.get(SnotifyService); fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; @@ -91,8 +87,6 @@ describe('NgSnotify Testing', () => { }); it('should create prompt toast with 4 buttons', (done) => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.debugElement.componentInstance; const service: SnotifyService = fixture.debugElement.injector.get(SnotifyService); fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; @@ -113,8 +107,6 @@ describe('NgSnotify Testing', () => { }); it('should create html toast with html content', (done) => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.debugElement.componentInstance; const service: SnotifyService = fixture.debugElement.injector.get(SnotifyService); fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; @@ -125,8 +117,6 @@ describe('NgSnotify Testing', () => { }); it('should create 3 toasts max at rightTop position', (done) => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.debugElement.componentInstance; const service: SnotifyService = fixture.debugElement.injector.get(SnotifyService); const compiled = fixture.debugElement.nativeElement; fixture.detectChanges(); @@ -150,8 +140,6 @@ describe('NgSnotify Testing', () => { }); it('should create toasts at different positions', (done) => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.debugElement.componentInstance; const service: SnotifyService = fixture.debugElement.injector.get(SnotifyService); fixture.detectChanges(); const compiled = fixture.debugElement.nativeElement; diff --git a/gulpfile.js b/gulpfile.js index c74a36c..7720493 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -167,7 +167,7 @@ gulp.task('copy:manifest', function () { * 9. Copy README.md from / to /dist */ gulp.task('copy:readme', function () { - return gulp.src([path.join(rootFolder, 'README.MD')]) + return gulp.src([path.join(rootFolder, 'README.md')]) .pipe(gulp.dest(distFolder)); }); diff --git a/package.json b/package.json index cf02c35..75c79f5 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "compodoc:serve": "npm run compodoc:build -- -s", "compodoc:watch": "npm run compodoc:build -- -s -w", "lint": "tslint --type-check -p src/tsconfig.es5.json src/**/*.ts", - "test": "npm run link:dist && tsc && karma start --single-run", + "test": "npm run link:dist && ng test", "lib:lint": "npm run lint && npm run example:lint", "lib:build": "npm run lib:lint && npm run build", "docs:build": "gitbook build ./docs ./demo/documentation",