Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make withResetModules "not async"
  • Loading branch information
rogeliog committed Jul 17, 2018
commit 1f86b12fefb07d118a70b9cc62c6c9511fd4841f
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ describe('withResetModules', () => {
it('resets all modules after the block', async () =>
createRuntime(__filename, {
moduleNameMapper,
}).then(async runtime => {
}).then(runtime => {
let exports;
await runtime.withResetModules(() => {
runtime.withResetModules(() => {
exports = runtime.requireModuleOrMock(
runtime.__mockRootPath,
'ModuleWithState',
Expand All @@ -223,9 +223,9 @@ describe('withResetModules', () => {
it('can call resetModules within a withResetModules block', async () =>
createRuntime(__filename, {
moduleNameMapper,
}).then(async runtime => {
}).then(runtime => {
let exports;
await runtime.withResetModules(() => {
runtime.withResetModules(() => {
exports = runtime.requireModuleOrMock(
runtime.__mockRootPath,
'ModuleWithState',
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-runtime/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,9 @@ class Runtime {
}
}

async withResetModules(fn: () => Promise<*> | void) {
withResetModules(fn: () => void) {
this._sandboxRegistries.unshift(Object.create(null));
await fn();
fn();
this._sandboxRegistries.shift();
}

Expand Down Expand Up @@ -892,8 +892,8 @@ class Runtime {
this.resetModules();
return jestObject;
};
const withResetModules = async (fn: () => Promise<*>) => {
await this.withResetModules(fn);
const withResetModules = (fn: () => void) => {
this.withResetModules(fn);
return jestObject;
};
const fn = this._moduleMocker.fn.bind(this._moduleMocker);
Expand Down
2 changes: 1 addition & 1 deletion types/Jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ export type Jest = {|
unmock(moduleName: string): Jest,
useFakeTimers(): Jest,
useRealTimers(): Jest,
withResetModules(fn: () => Promise<*>): Promise<Jest>,
withResetModules(fn: () => void): Jest,
|};