From 6ed5dca8ce4b8b70bccb67e28b9ac57890a10a36 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sat, 30 Jan 2021 12:43:13 -0600 Subject: [PATCH] add tests for editor reducers --- src/editor/reducers.test.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/editor/reducers.test.ts diff --git a/src/editor/reducers.test.ts b/src/editor/reducers.test.ts new file mode 100644 index 00000000..b53531bc --- /dev/null +++ b/src/editor/reducers.test.ts @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2021 The Pybricks Authors + +import { Ace } from 'ace-builds'; +import { Action } from '../actions'; +import { setEditSession } from './actions'; +import reducers from './reducers'; + +type State = ReturnType; + +test('initial state', () => { + expect(reducers(undefined, {} as Action)).toMatchInlineSnapshot(` + Object { + "current": null, + } + `); +}); + +test('current', () => { + const session = {} as Ace.EditSession; + expect(reducers({ current: null } as State, setEditSession(session)).current).toBe( + session, + ); + expect( + reducers({ current: session } as State, setEditSession(undefined)).current, + ).toBe(null); +});