Fix tests

This commit is contained in:
ziajka 2018-07-06 10:17:34 +02:00
parent 290ce6641f
commit 65c0739b3e
3 changed files with 13 additions and 9 deletions

View File

@ -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",

View File

@ -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();
});
});

View File

@ -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"