Skip to content

Commit 815b394

Browse files
test(overmind): fix operator tests to match new API
1 parent dd0e3d2 commit 815b394

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

packages/node_modules/overmind/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,9 @@ export function action<Input, ThisConfig extends Configuration = Config>(
10041004

10051005
export function fork<
10061006
Input,
1007+
// The Output should not really be ANY here, as it will type the last operator
1008+
// input as ANY, but no way to infer this either... so either force to same as Input
1009+
// or last will be ANY
10071010
Paths extends { [key: string]: IOperator<ThisConfig, Input, any> },
10081011
ThisConfig extends Configuration = Config
10091012
>(

packages/node_modules/overmind/src/operators.test.ts

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ describe('OPERATORS', () => {
1919
test('map', () => {
2020
expect.assertions(1)
2121
const test: Operator<string> = pipe(
22-
map(({ value }) => value.toUpperCase()),
23-
action(({ value, state }) => (state.foo = value))
22+
map((_, value) => value.toUpperCase()),
23+
action(({ state }, value) => (state.foo = value))
2424
)
2525

2626
const state = {
@@ -48,8 +48,8 @@ describe('OPERATORS', () => {
4848
test('map (async)', () => {
4949
expect.assertions(1)
5050
const test: Operator<string> = pipe(
51-
map(({ value }) => Promise.resolve(value.toUpperCase())),
52-
action(({ value, state }) => (state.foo = value))
51+
map((_, value) => Promise.resolve(value.toUpperCase())),
52+
action(({ state }, value) => (state.foo = value))
5353
)
5454

5555
const state = {
@@ -143,9 +143,9 @@ describe('OPERATORS', () => {
143143
test('filter - truthy', () => {
144144
expect.assertions(1)
145145
const test: Operator<string> = pipe(
146-
filter(({ value }) => value === 'foo'),
147-
map(({ value }) => value.toUpperCase()),
148-
action(({ value, state }) => (state.foo = value))
146+
filter((_, value) => value === 'foo'),
147+
map((_, value) => value.toUpperCase()),
148+
action(({ state }, value) => (state.foo = value))
149149
)
150150

151151
const state = {
@@ -164,18 +164,16 @@ describe('OPERATORS', () => {
164164
interface Operator<Input = void, Output = Input>
165165
extends IOperator<Config, Input, Output> {}
166166

167-
interface Action<Input = void> extends IAction<Config, Input> {}
168-
169167
return overmind.actions.test('foo').then(() => {
170168
expect(overmind.state.foo).toBe('FOO')
171169
})
172170
})
173171

174172
test('filter - falsy', () => {
175173
const test: Operator<string> = pipe(
176-
filter(({ value }) => value === 'bar'),
177-
map(({ value }) => value.toUpperCase()),
178-
action(({ value, state }) => (state.foo = value))
174+
filter((_, value) => value === 'bar'),
175+
map((_, value) => value.toUpperCase()),
176+
action(({ state }, value) => (state.foo = value))
179177
)
180178

181179
const state = {
@@ -194,8 +192,6 @@ describe('OPERATORS', () => {
194192
interface Operator<Input = void, Output = Input>
195193
extends IOperator<Config, Input, Output> {}
196194

197-
interface Action<Input = void> extends IAction<Config, Input> {}
198-
199195
return overmind.actions.test('foo').then(() => {
200196
expect(overmind.state.foo).toBe('bar')
201197
})
@@ -206,8 +202,8 @@ describe('OPERATORS', () => {
206202
const test: Operator<string> = pipe(
207203
fork(() => 'foo', {
208204
foo: pipe(
209-
map(({ value }) => value.toUpperCase()),
210-
action(({ value, state }) => (state.foo = value))
205+
map((_, value) => value.toUpperCase()),
206+
action(({ state }, value) => (state.foo = value))
211207
),
212208
})
213209
)
@@ -240,12 +236,12 @@ describe('OPERATORS', () => {
240236
const test: Operator<string, string | number> = pipe(
241237
when(() => true, {
242238
true: pipe(
243-
map(({ value }) => value.toUpperCase()),
244-
action(({ value, state }) => (state.foo = value))
239+
map((_, value) => value.toUpperCase()),
240+
action(({ state }, value) => (state.foo = value))
245241
),
246242
false: pipe(
247-
map(({ value }) => Number(value)),
248-
action(({ value, state }) => (state.number = value))
243+
map((_, value) => Number(value)),
244+
action(({ state }, value) => (state.number = value))
249245
),
250246
})
251247
)
@@ -320,8 +316,6 @@ describe('OPERATORS', () => {
320316
interface Operator<Input = void, Output = Input>
321317
extends IOperator<Config, Input, Output> {}
322318

323-
interface Action<Input = void> extends IAction<Config, Input> {}
324-
325319
return Promise.all([overmind.actions.test(), overmind.actions.test()]).then(
326320
() => {
327321
expect(overmind.state.runCount).toBe(1)

0 commit comments

Comments
 (0)