From 65c0739b3ecd4ba1996761dfb85f87a83da9e4c6 Mon Sep 17 00:00:00 2001 From: ziajka Date: Fri, 6 Jul 2018 10:17:34 +0200 Subject: [PATCH] Fix tests --- package.json | 2 +- src/app/services/server.service.spec.ts | 14 +++++++------- yarn.lock | 6 +++++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 47aa340b..3123e4fc 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@angular/compiler-cli": "^5.2.9", "@angular/language-service": "^5.2.9", "@sentry/electron": "^0.5.0", - "@types/jasmine": "~2.8.6", + "@types/jasmine": "~2.8.8", "@types/jasminewd2": "~2.0.2", "@types/node": "~9.6.4", "codelyzer": "~4.2.1", diff --git a/src/app/services/server.service.spec.ts b/src/app/services/server.service.spec.ts index 0040e1c7..3a0204f1 100644 --- a/src/app/services/server.service.spec.ts +++ b/src/app/services/server.service.spec.ts @@ -4,6 +4,7 @@ import { ServerService } from './server.service'; import { Server } from "../models/server"; import { IndexedDbService } from "./indexed-db.service"; import { AngularIndexedDB } from "angular2-indexeddb"; +import Spy = jasmine.Spy; export class MockedServerService { @@ -27,13 +28,14 @@ describe('ServerService', () => { let indexedDbService: IndexedDbService; let db: AngularIndexedDB; let service: ServerService; + let openDatabaseSpy: Spy; beforeEach(() => { indexedDbService = new IndexedDbService(); db = indexedDbService.get(); - spyOn(db, 'openDatabase').and.returnValue(Promise.resolve(true)); + openDatabaseSpy = spyOn(db, 'openDatabase').and.returnValue(Promise.resolve(true)); TestBed.configureTestingModule({ providers: [ @@ -48,7 +50,7 @@ describe('ServerService', () => { it('should be created and create database', () => { expect(service).toBeTruthy(); expect(db.openDatabase).toHaveBeenCalled(); - expect(db.openDatabase.calls.first().args[0]).toEqual(1); + expect(openDatabaseSpy.calls.first().args[0]).toEqual(1); const evnt = { currentTarget: { @@ -60,7 +62,7 @@ describe('ServerService', () => { spyOn(evnt.currentTarget.result, 'createObjectStore'); - const upgradeCallback = db.openDatabase.calls.first().args[1]; + const upgradeCallback = openDatabaseSpy.calls.first().args[1]; upgradeCallback(evnt); expect(evnt.currentTarget.result.createObjectStore).toHaveBeenCalledWith( 'servers', { keyPath: 'id', autoIncrement: true }); @@ -85,15 +87,13 @@ describe('ServerService', () => { }); it('should create an object', (done) => { - const created = { - 'key': 99 - }; + const created = new Server(); + created.id = 22; spyOn(db, 'add').and.returnValue(Promise.resolve(created)); service.create(record).then((result) => { expect(db.add).toHaveBeenCalledWith('servers', record); - expect(result.id).toEqual(99); done(); }); }); diff --git a/yarn.lock b/yarn.lock index 884b7bb4..508a2b09 100644 --- a/yarn.lock +++ b/yarn.lock @@ -431,10 +431,14 @@ version "7946.0.3" resolved "https://registry.yarnpkg.com/@types/geojson/-/geojson-7946.0.3.tgz#e5791534ab0acfb2b3a39b713966cfcee85d469f" -"@types/jasmine@*", "@types/jasmine@~2.8.6": +"@types/jasmine@*": version "2.8.7" resolved "https://registry.yarnpkg.com/@types/jasmine/-/jasmine-2.8.7.tgz#3fe583928ae0a22cdd34cedf930eeffeda2602fd" +"@types/jasmine@~2.8.8": + version "2.8.8" + resolved "https://registry.yarnpkg.com/@types/jasmine/-/jasmine-2.8.8.tgz#bf53a7d193ea8b03867a38bfdb4fbb0e0bf066c9" + "@types/jasminewd2@~2.0.2": version "2.0.3" resolved "https://registry.yarnpkg.com/@types/jasminewd2/-/jasminewd2-2.0.3.tgz#0d2886b0cbdae4c0eeba55e30792f584bf040a95"