-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from meteorrn/feature/optional-netinfo
feature: make NetInfo injectable/truly optional
- Loading branch information
Showing
5 changed files
with
130 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import sinon from 'sinon'; | ||
import Meteor from '../src/Meteor'; | ||
|
||
export const stubs = new Map(); | ||
|
||
export const stub = (target, name, handler) => { | ||
if (stubs.get(target)) { | ||
throw new Error(`already stubbed: ${name}`); | ||
} | ||
const stubbedTarget = sinon.stub(target, name); | ||
if (typeof handler === 'function') { | ||
stubbedTarget.callsFake(handler); | ||
} else { | ||
stubbedTarget.value(handler); | ||
} | ||
stubs.set(stubbedTarget, name); | ||
}; | ||
|
||
export const restore = (target, name) => { | ||
if (!target[name] || !target[name].restore) { | ||
throw new Error(`not stubbed: ${name}`); | ||
} | ||
target[name].restore(); | ||
stubs.delete(target); | ||
}; | ||
|
||
export const overrideStub = (target, name, handler) => { | ||
restore(target, name); | ||
stub(target, name, handler); | ||
}; | ||
|
||
export const restoreAll = () => { | ||
stubs.forEach((name, target) => { | ||
stubs.delete(target); | ||
target.restore(); | ||
}); | ||
}; | ||
|
||
export const awaitDisconnected = async () => { | ||
Meteor.disconnect(); | ||
await new Promise((resolve) => { | ||
let timer = setInterval(() => { | ||
if (Meteor.status().status === 'disconnected') { | ||
clearInterval(timer); | ||
resolve(); | ||
} | ||
}, 100); | ||
}); | ||
}; |