diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2018-02-20 16:24:41 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-02-20 17:48:28 +0100 |
| commit | 1214138633bcca19a1b96622400f3fbcf4044bd9 (patch) | |
| tree | 0cf470c59b4c7c8a6327e64610f68f5facd78d6d | |
| parent | 9fa6ddc1cebae32b6df4ac1f58baa0aee08a9549 (diff) | |
| download | mullvadvpn-1214138633bcca19a1b96622400f3fbcf4044bd9.tar.xz mullvadvpn-1214138633bcca19a1b96622400f3fbcf4044bd9.zip | |
Fix annotations in IPC chain
| -rw-r--r-- | test/helpers/IpcChain.js | 27 | ||||
| -rw-r--r-- | test/helpers/ipc-helpers.js | 2 |
2 files changed, 15 insertions, 14 deletions
diff --git a/test/helpers/IpcChain.js b/test/helpers/IpcChain.js index a62626a6a6..4e3ddea79e 100644 --- a/test/helpers/IpcChain.js +++ b/test/helpers/IpcChain.js @@ -7,7 +7,7 @@ export class IpcChain { _expectedCalls: Array<string>; _recordedCalls: Array<string>; _mockIpc: {}; - _done: (*) => void; + _done: (?Error) => void; _aborted: boolean; constructor(mockIpc: {}) { @@ -17,28 +17,29 @@ export class IpcChain { this._aborted = false; } - require(ipcCall: string): StepBuilder { + require<R>(ipcCall: string): StepBuilder<R> { this._expectedCalls.push(ipcCall); return new StepBuilder(ipcCall, this._addStep.bind(this)); } - _addStep(step: StepBuilder) { + _addStep<R>(step: StepBuilder<R>) { const me = this; this._mockIpc[step.ipcCall] = function() { return new Promise(r => me._stepPromiseCallback(step, r, arguments)); }; } - _stepPromiseCallback(step, resolve, args) { + _stepPromiseCallback<R>(step: StepBuilder<R>, resolve: (?R) => void, args: Array<mixed>) { if (this._aborted) { return; } this._registerCall(step.ipcCall); - if (step.inputValidation) { + const inputValidation = step.inputValidation; + if (inputValidation) { const failedInputValidation = failFast(() => { - step.inputValidation(...args); + inputValidation(...args); }, this._done); if (failedInputValidation) { @@ -77,23 +78,23 @@ export class IpcChain { } } -class StepBuilder { +class StepBuilder<R> { ipcCall: string; - inputValidation: () => void; - returnValue: *; - _cb: (StepBuilder) => void; + inputValidation: ?() => void; + returnValue: ?R; + _cb: (StepBuilder<R>) => void; - constructor(ipcCall: string, cb: (StepBuilder)=> void) { + constructor(ipcCall: string, cb: (StepBuilder<R>) => void) { this.ipcCall = ipcCall; this._cb = cb; } - withInputValidation(iv: () => void): StepBuilder { + withInputValidation(iv: () => void): this { this.inputValidation = iv; return this; } - withReturnValue(rv: *): StepBuilder { + withReturnValue(rv: R): this { this.returnValue = rv; return this; } diff --git a/test/helpers/ipc-helpers.js b/test/helpers/ipc-helpers.js index 2a2dd1e6b8..3f8307ccf3 100644 --- a/test/helpers/ipc-helpers.js +++ b/test/helpers/ipc-helpers.js @@ -6,7 +6,7 @@ import configureStore from '../../app/redux/store'; import { createMemoryHistory } from 'history'; import { mockStore } from '../mocks/redux'; -type DoneCallback = (?mixed) => void; +type DoneCallback = (?Error) => void; type Check = () => void; export function setupIpcAndStore() { |
