-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7cc71c
commit 60e7bd3
Showing
8 changed files
with
160 additions
and
164 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,5 +1 @@ | ||
export default { | ||
semi: false, | ||
singleQuote: true, | ||
trailingComma: 'es5', | ||
} | ||
export default {}; |
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 |
---|---|---|
@@ -1,133 +1,133 @@ | ||
import { AnyAction } from 'redux' | ||
import { call, CallEffect } from 'redux-saga/effects' | ||
import { AnyAction } from "redux"; | ||
import { call, CallEffect } from "redux-saga/effects"; | ||
|
||
import { deferredAction, standardAction } from '../index' | ||
import { deferredAction, standardAction } from "../index"; | ||
|
||
describe('standardAction()', () => { | ||
const IO = { stdout: jest.fn() } | ||
describe("standardAction()", () => { | ||
const IO = { stdout: jest.fn() }; | ||
|
||
it('yields to the passed generator', () => { | ||
it("yields to the passed generator", () => { | ||
function* aSaga(io: typeof IO, action: { type: string }) { | ||
yield call(io.stdout, action.type) | ||
yield call(io.stdout, action.type); | ||
} | ||
|
||
const iterator = standardAction(aSaga, IO)({ type: 'AN_ACTION' }) | ||
const iterator = standardAction(aSaga, IO)({ type: "AN_ACTION" }); | ||
|
||
expect(iterator.next().value).toEqual( | ||
call(aSaga, IO, { type: 'AN_ACTION' }) | ||
) | ||
}) | ||
call(aSaga, IO, { type: "AN_ACTION" }) | ||
); | ||
}); | ||
|
||
it('catches if the delegate saga throws', () => { | ||
it("catches if the delegate saga throws", () => { | ||
// eslint-disable-next-line require-yield | ||
function* aSaga(_io: typeof IO, _action: AnyAction) { | ||
throw new Error('oops') | ||
throw new Error("oops"); | ||
} | ||
|
||
const iterator = standardAction(aSaga, IO)({ type: 'AN_ACTION' }) | ||
const { done: doneA, value: valueA } = iterator.next() | ||
const iterator = standardAction(aSaga, IO)({ type: "AN_ACTION" }); | ||
const { done: doneA, value: valueA } = iterator.next(); | ||
|
||
expect(doneA).toEqual(false) | ||
expect(doneA).toEqual(false); | ||
|
||
expect(valueA).toEqual(call(aSaga, IO, { type: 'AN_ACTION' })) | ||
expect(valueA).toEqual(call(aSaga, IO, { type: "AN_ACTION" })); | ||
|
||
const { value: valueB } = iterator.throw(Error('oops')) | ||
const { value: valueB } = iterator.throw(Error("oops")); | ||
|
||
expect(valueB).toEqual(call(IO.stdout, 'aSaga', Error('oops'))) | ||
}) | ||
}) | ||
expect(valueB).toEqual(call(IO.stdout, "aSaga", Error("oops"))); | ||
}); | ||
}); | ||
|
||
describe('deferredAction()', () => { | ||
describe("deferredAction()", () => { | ||
const IO = { | ||
echo: <T>(msg: T) => msg, | ||
sayNum: (num: number) => num, | ||
sayStr: (str: string) => str, | ||
stdout: jest.fn(), | ||
} | ||
}; | ||
|
||
it('yields to the passed generator', () => { | ||
it("yields to the passed generator", () => { | ||
const action = { | ||
type: 'AN_ACTION', | ||
type: "AN_ACTION", | ||
meta: { | ||
deferred: { | ||
success: jest.fn(), | ||
failure: jest.fn(), | ||
}, | ||
}, | ||
} | ||
}; | ||
|
||
function* aSaga(io: typeof IO, _action: AnyAction) { | ||
yield call(io.sayNum, 123) | ||
yield call(io.sayStr, 'hello') | ||
yield call(io.sayNum, 123); | ||
yield call(io.sayStr, "hello"); | ||
} | ||
|
||
// This generator is *not* "aSaga", but instead the wrapper saga | ||
const iterator = deferredAction(aSaga, IO)(action) | ||
const iterator = deferredAction(aSaga, IO)(action); | ||
|
||
expect(iterator.next().value).toEqual(call(aSaga, IO, action)) | ||
expect(iterator.next().value).toEqual(call(aSaga, IO, action)); | ||
|
||
expect(iterator.next('yielded').value).toEqual( | ||
call(action.meta.deferred.success, 'yielded') | ||
) | ||
}) | ||
expect(iterator.next("yielded").value).toEqual( | ||
call(action.meta.deferred.success, "yielded") | ||
); | ||
}); | ||
|
||
it('catches if the delegate saga throws', () => { | ||
it("catches if the delegate saga throws", () => { | ||
const action = { | ||
type: 'AN_ACTION', | ||
type: "AN_ACTION", | ||
meta: { | ||
deferred: { | ||
success: jest.fn(), | ||
failure: jest.fn(), | ||
}, | ||
}, | ||
} | ||
}; | ||
|
||
// eslint-disable-next-line require-yield | ||
function* aSaga(_io: typeof IO, _action: AnyAction) { | ||
throw new Error('welp...') | ||
throw new Error("welp..."); | ||
} | ||
|
||
const iterator = deferredAction(aSaga, IO)(action) | ||
const iterator = deferredAction(aSaga, IO)(action); | ||
|
||
expect(iterator.next().value).toEqual(call(aSaga, IO, action)) | ||
expect(iterator.next().value).toEqual(call(aSaga, IO, action)); | ||
|
||
expect(iterator.throw(Error('welp...')).value).toEqual( | ||
call(IO.stdout, 'aSaga', Error('welp...')) | ||
) | ||
expect(iterator.throw(Error("welp...")).value).toEqual( | ||
call(IO.stdout, "aSaga", Error("welp...")) | ||
); | ||
|
||
expect(iterator.next().value).toEqual( | ||
call(action.meta.deferred.failure, Error('welp...')) | ||
) | ||
}) | ||
call(action.meta.deferred.failure, Error("welp...")) | ||
); | ||
}); | ||
|
||
it('passes the rest of meta', () => { | ||
it("passes the rest of meta", () => { | ||
const action = { | ||
type: 'AN_ACTION', | ||
type: "AN_ACTION", | ||
meta: { | ||
foobat: 'hey', | ||
foobat: "hey", | ||
deferred: { | ||
success: jest.fn(), | ||
failure: jest.fn(), | ||
}, | ||
}, | ||
} | ||
}; | ||
|
||
function* aSaga( | ||
io: typeof IO, | ||
_action: AnyAction | ||
): Generator<CallEffect<unknown>> { | ||
const result = yield call(io.echo, 'A message') | ||
const result = yield call(io.echo, "A message"); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
return result | ||
return result; | ||
} | ||
|
||
const iterator = deferredAction(aSaga, IO)(action) | ||
const iterator = deferredAction(aSaga, IO)(action); | ||
|
||
expect(iterator.next().value).toEqual(call(aSaga, IO, action)) | ||
expect(iterator.next().value).toEqual(call(aSaga, IO, action)); | ||
|
||
expect(iterator.next('A message').value).toEqual( | ||
call(action.meta.deferred.success, 'A message') | ||
) | ||
}) | ||
}) | ||
expect(iterator.next("A message").value).toEqual( | ||
call(action.meta.deferred.success, "A message") | ||
); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,113 +1,113 @@ | ||
import { AnyAction } from 'redux' | ||
import { call as tCall } from 'typed-redux-saga' | ||
import { call } from 'redux-saga/effects' | ||
import { AnyAction } from "redux"; | ||
import { call as tCall } from "typed-redux-saga"; | ||
import { call } from "redux-saga/effects"; | ||
|
||
import { | ||
typedStandardAction as standardAction, | ||
typedDeferredAction as deferredAction, | ||
} from '../index' | ||
} from "../index"; | ||
|
||
describe('typedStandardAction()', () => { | ||
it('yields to the passed generator', () => { | ||
const IO = { stdout: jest.fn() } | ||
describe("typedStandardAction()", () => { | ||
it("yields to the passed generator", () => { | ||
const IO = { stdout: jest.fn() }; | ||
|
||
function* aSaga(io: typeof IO, action: AnyAction) { | ||
yield call(io.stdout, action.type) | ||
yield call(io.stdout, action.type); | ||
} | ||
|
||
const iterator = standardAction(aSaga, IO)({ type: 'AN_ACTION' }) | ||
const iterator = standardAction(aSaga, IO)({ type: "AN_ACTION" }); | ||
|
||
expect(iterator.next().value).toEqual( | ||
call(aSaga, IO, { type: 'AN_ACTION' }) | ||
) | ||
}) | ||
call(aSaga, IO, { type: "AN_ACTION" }) | ||
); | ||
}); | ||
|
||
it('catches if the delegate saga throws', () => { | ||
const IO = { stdout: jest.fn() } | ||
it("catches if the delegate saga throws", () => { | ||
const IO = { stdout: jest.fn() }; | ||
|
||
// eslint-disable-next-line require-yield | ||
function* aSaga(_io: typeof IO, _action: AnyAction) { | ||
throw new Error('oops') | ||
throw new Error("oops"); | ||
} | ||
|
||
const iterator = standardAction(aSaga, IO)({ type: 'AN_ACTION' }) | ||
const iterator = standardAction(aSaga, IO)({ type: "AN_ACTION" }); | ||
|
||
const { done: doneA, value: valueA } = iterator.next() | ||
const { done: doneA, value: valueA } = iterator.next(); | ||
|
||
expect(doneA).toEqual(false) | ||
expect(doneA).toEqual(false); | ||
|
||
expect(valueA).toEqual(call(aSaga, IO, { type: 'AN_ACTION' })) | ||
expect(valueA).toEqual(call(aSaga, IO, { type: "AN_ACTION" })); | ||
|
||
const { value: valueB } = iterator.throw(Error('oops')) | ||
const { value: valueB } = iterator.throw(Error("oops")); | ||
|
||
expect(valueB).toEqual(call(IO.stdout, 'aSaga', Error('oops'))) | ||
}) | ||
}) | ||
expect(valueB).toEqual(call(IO.stdout, "aSaga", Error("oops"))); | ||
}); | ||
}); | ||
|
||
describe('typedDeferredAction()', () => { | ||
it('yields to the passed generator', () => { | ||
describe("typedDeferredAction()", () => { | ||
it("yields to the passed generator", () => { | ||
const IO = { | ||
echo: <T>(msg: T) => msg, | ||
sayNum: (num: number) => num, | ||
stdout: jest.fn(), | ||
} | ||
}; | ||
|
||
const action = { | ||
type: 'AN_ACTION', | ||
type: "AN_ACTION", | ||
meta: { | ||
deferred: { | ||
success: jest.fn(), | ||
failure: jest.fn(), | ||
}, | ||
}, | ||
} | ||
}; | ||
|
||
function* aSaga(io: typeof IO, _action: typeof action) { | ||
const aNumber = yield* tCall(io.sayNum, 1) | ||
const aNumber = yield* tCall(io.sayNum, 1); | ||
|
||
return aNumber | ||
return aNumber; | ||
} | ||
|
||
const iterator = deferredAction(aSaga, IO)(action) | ||
const iterator = deferredAction(aSaga, IO)(action); | ||
|
||
expect(iterator.next().value).toEqual(call(aSaga, IO, action)) | ||
expect(iterator.next().value).toEqual(call(aSaga, IO, action)); | ||
|
||
expect(iterator.next('A message').value).toEqual( | ||
call(action.meta.deferred.success, 'A message') | ||
) | ||
}) | ||
expect(iterator.next("A message").value).toEqual( | ||
call(action.meta.deferred.success, "A message") | ||
); | ||
}); | ||
|
||
it('catches if the delegate saga throws', () => { | ||
it("catches if the delegate saga throws", () => { | ||
const IO = { | ||
stdout: jest.fn(), | ||
echo: (msg: unknown) => msg, | ||
} | ||
}; | ||
|
||
const action = { | ||
type: 'AN_ACTION', | ||
type: "AN_ACTION", | ||
meta: { | ||
deferred: { | ||
success: jest.fn(), | ||
failure: jest.fn(), | ||
}, | ||
}, | ||
} | ||
}; | ||
|
||
// eslint-disable-next-line require-yield | ||
function* aSaga(_io: typeof IO, _action: typeof action) { | ||
throw new Error('welp...') | ||
throw new Error("welp..."); | ||
} | ||
|
||
const iterator = deferredAction(aSaga, IO)(action) | ||
const iterator = deferredAction(aSaga, IO)(action); | ||
|
||
expect(iterator.next().value).toEqual(call(aSaga, IO, action)) | ||
expect(iterator.next().value).toEqual(call(aSaga, IO, action)); | ||
|
||
expect(iterator.throw(Error('welp...')).value).toEqual( | ||
call(IO.stdout, 'aSaga', Error('welp...')) | ||
) | ||
expect(iterator.throw(Error("welp...")).value).toEqual( | ||
call(IO.stdout, "aSaga", Error("welp...")) | ||
); | ||
|
||
expect(iterator.next().value).toEqual( | ||
call(action.meta.deferred.failure, Error('welp...')) | ||
) | ||
}) | ||
}) | ||
call(action.meta.deferred.failure, Error("welp...")) | ||
); | ||
}); | ||
}); |
Oops, something went wrong.