Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#110 add support for getContext and setContext side effects
- Loading branch information
Showing
10 changed files
with
182 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { getContext } from 'redux-saga/effects'; | ||
import expectSaga from 'expectSaga'; | ||
import { errorRegex, unreachableError } from './_helper'; | ||
|
||
function* saga() { | ||
yield getContext('theAnswer'); | ||
} | ||
|
||
test('getContext assertion passes', () => | ||
expectSaga(saga) | ||
.getContext('theAnswer') | ||
.run()); | ||
|
||
test('negative getContext assertion passes with wrong property name', () => | ||
expectSaga(saga) | ||
.not.getContext('wrongAnswer') | ||
.run()); | ||
|
||
test('getContext assertion fails with wrong property name', () => | ||
expectSaga(saga) | ||
.getContext('wrongAnswer') | ||
.run() | ||
.then(unreachableError) | ||
.catch(e => { | ||
expect(e.message).toMatch(errorRegex); | ||
})); | ||
|
||
test('negative getContext assertion fails with correct property name', () => | ||
expectSaga(saga) | ||
.not.getContext('theAnswer') | ||
.run() | ||
.then(unreachableError) | ||
.catch(e => { | ||
expect(e.message).toMatch(errorRegex); | ||
})); |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { setContext } from 'redux-saga/effects'; | ||
import expectSaga from 'expectSaga'; | ||
import { errorRegex, unreachableError } from './_helper'; | ||
|
||
function* saga() { | ||
yield setContext({ answer: 42 }); | ||
} | ||
|
||
test('setContext assertion passes', () => | ||
expectSaga(saga) | ||
.setContext({ answer: 42 }) | ||
.run()); | ||
|
||
test('negative setContext assertion passes with wrong properties', () => | ||
expectSaga(saga) | ||
.not.setContext({ answer: 41 }) | ||
.run()); | ||
|
||
test('setContext assertion fails with wrong properties', () => | ||
expectSaga(saga) | ||
.setContext({ answer: 41 }) | ||
.run() | ||
.then(unreachableError) | ||
.catch(e => { | ||
expect(e.message).toMatch(errorRegex); | ||
})); | ||
|
||
test('negative setContext assertion fails with correct properties', () => | ||
expectSaga(saga) | ||
.not.setContext({ answer: 42 }) | ||
.run() | ||
.then(unreachableError) | ||
.catch(e => { | ||
expect(e.message).toMatch(errorRegex); | ||
})); |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// @flow | ||
import { getContext, put } from 'redux-saga/effects'; | ||
import expectSaga from 'expectSaga'; | ||
import * as m from 'expectSaga/matchers'; | ||
import { dynamic } from 'expectSaga/providers'; | ||
|
||
const contextVar = 'contextValue'; | ||
|
||
function* saga() { | ||
const value = yield getContext(contextVar); | ||
|
||
yield put({ type: 'DONE', payload: value }); | ||
} | ||
|
||
test('uses provided value for `getContext`', () => | ||
expectSaga(saga) | ||
.provide({ | ||
getContext(property, next) { | ||
if (property === contextVar) { | ||
return 42; | ||
} | ||
|
||
return next(); | ||
}, | ||
}) | ||
.put({ type: 'DONE', payload: 42 }) | ||
.run()); | ||
|
||
test('uses static provided values from redux-saga/effects', () => | ||
expectSaga(saga) | ||
.provide([[getContext(contextVar), 42]]) | ||
.put({ type: 'DONE', payload: 42 }) | ||
.run()); | ||
|
||
test('uses static provided values from matchers', () => | ||
expectSaga(saga) | ||
.provide([[m.getContext(contextVar), 42]]) | ||
.put({ type: 'DONE', payload: 42 }) | ||
.run()); | ||
|
||
test('dynamic values have access to effect', () => | ||
expectSaga(saga) | ||
.provide([ | ||
[ | ||
m.getContext(contextVar), | ||
dynamic(property => { | ||
expect(property).toBe(contextVar); | ||
return 42; | ||
}), | ||
], | ||
]) | ||
.put({ type: 'DONE', payload: 42 }) | ||
.run()); |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// @flow | ||
import { setContext } from 'redux-saga/effects'; | ||
import expectSaga from 'expectSaga'; | ||
|
||
function* saga() { | ||
yield setContext({ answer: 42 }); | ||
} | ||
|
||
test('dynamic values have access to effect', () => | ||
expectSaga(saga) | ||
.provide({ | ||
setContext(properties, next) { | ||
expect(properties.answer).toBe(42); | ||
return next(); | ||
}, | ||
}) | ||
.run()); |
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
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
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
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
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
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