From 0baba65686aa9d85902e589c2a134b3265c559f9 Mon Sep 17 00:00:00 2001 From: Xymorot Date: Sat, 25 Jul 2020 22:28:55 +0200 Subject: [PATCH] fix: do not load mocks in container.ts since they are not available in the built app --- src/main/core/container.ts | 10 ---------- src/main/modules/web-crawler/web-crawler.spec.ts | 11 ++++++++--- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/main/core/container.ts b/src/main/core/container.ts index 3ac079b..9a60ae0 100644 --- a/src/main/core/container.ts +++ b/src/main/core/container.ts @@ -5,21 +5,11 @@ import { NhentaiApi } from '../modules/nhentai/nhentai-api'; import '../modules/nhentai/nhentai-ipc-controller'; import { Session } from '../modules/session/session'; import { Store } from '../modules/store/store'; -import { StoreMock } from '../modules/store/store.mock'; import { WebCrawler } from '../modules/web-crawler/web-crawler'; export const container = new Container({ defaultScope: 'Singleton' }); container.bind(Symbol.for('store')).to(Store); -export function mockStore(unMock = false): void { - if (unMock) { - container.unbind(Symbol.for('store')); - container.bind(Symbol.for('store')).to(Store); - } else { - container.unbind(Symbol.for('store')); - container.bind(Symbol.for('store')).to(StoreMock); - } -} container.bind(Symbol.for('web-crawler')).to(WebCrawler); diff --git a/src/main/modules/web-crawler/web-crawler.spec.ts b/src/main/modules/web-crawler/web-crawler.spec.ts index ef4e349..d1b5710 100644 --- a/src/main/modules/web-crawler/web-crawler.spec.ts +++ b/src/main/modules/web-crawler/web-crawler.spec.ts @@ -6,7 +6,9 @@ import 'mocha'; import nock from 'nock'; import { Response } from 'node-fetch'; import sinon from 'sinon'; -import { container, mockStore } from '../../core/container'; +import { container } from '../../core/container'; +import { Store } from '../store/store'; +import { StoreMock } from '../store/store.mock'; import { IWebCrawler } from './i-web-crawler'; describe('Web Crawler', function () { @@ -15,7 +17,8 @@ describe('Web Crawler', function () { before(() => { rewiremock.enable(); - mockStore(); + container.unbind(Symbol.for('store')); + container.bind(Symbol.for('store')).to(StoreMock); }); beforeEach(() => { @@ -30,7 +33,9 @@ describe('Web Crawler', function () { after(() => { rewiremock.disable(); - mockStore(true); + + container.unbind(Symbol.for('store')); + container.bind(Symbol.for('store')).to(Store); }); it('fetches websites', async () => {