Skip to content

Commit ed8615f

Browse files
committed
Fix updateSnapshot resetting after updating snapshots in watch mode
1 parent 2daf8fe commit ed8615f

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

packages/jest-cli/src/__tests__/watch.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ describe('Watch mode flows', () => {
257257
});
258258

259259
it('Pressing "u" reruns the tests in "update snapshot" mode', () => {
260+
globalConfig.updateSnapshot = 'new';
261+
260262
watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);
261263
runJestMock.mockReset();
262264

@@ -270,7 +272,7 @@ describe('Watch mode flows', () => {
270272
stdin.emit(KEYS.A);
271273
// updateSnapshot is not sticky after a run.
272274
expect(runJestMock.mock.calls[1][0].globalConfig).toMatchObject({
273-
updateSnapshot: 'none',
275+
updateSnapshot: 'new',
274276
watch: false,
275277
});
276278
});

packages/jest-cli/src/watch.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,15 @@ export default function watch(
212212
startRun(globalConfig);
213213
break;
214214
case KEYS.U:
215+
const previousUpdateSnapshot = globalConfig.updateSnapshot;
216+
215217
globalConfig = updateGlobalConfig(globalConfig, {
216218
updateSnapshot: 'all',
217219
});
218220
startRun(globalConfig);
219221
globalConfig = updateGlobalConfig(globalConfig, {
220222
// updateSnapshot is not sticky after a run.
221-
updateSnapshot: 'none',
223+
updateSnapshot: previousUpdateSnapshot,
222224
});
223225
break;
224226
case KEYS.A:

0 commit comments

Comments
 (0)