Add wrapSelectors functionality
This commit is contained in:
@@ -326,6 +326,122 @@ describe("bound system", function(){
|
||||
|
||||
})
|
||||
|
||||
describe('wrapSelectors', () => {
|
||||
it("should wrap a selector and provide a reference to the original", function(){
|
||||
|
||||
// Given
|
||||
const system = new System({
|
||||
plugins: [
|
||||
{
|
||||
statePlugins: {
|
||||
doge: {
|
||||
selectors: {
|
||||
wow: () => (system) => {
|
||||
return "original"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
statePlugins: {
|
||||
doge: {
|
||||
wrapSelectors: {
|
||||
wow: (ori) => (system) => {
|
||||
// Then
|
||||
return ori() + " wrapper"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
// When
|
||||
var res = system.getSystem().dogeSelectors.wow(1)
|
||||
expect(res).toEqual("original wrapper")
|
||||
|
||||
})
|
||||
|
||||
it("should provide a live reference to the system to a wrapper", function(done){
|
||||
|
||||
// Given
|
||||
const mySystem = new System({
|
||||
plugins: [
|
||||
{
|
||||
statePlugins: {
|
||||
doge: {
|
||||
selectors: {
|
||||
wow: () => (system) => {
|
||||
return "original"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
statePlugins: {
|
||||
doge: {
|
||||
wrapSelectors: {
|
||||
wow: (ori, system) => () => {
|
||||
// Then
|
||||
expect(mySystem.getSystem()).toEqual(system.getSystem())
|
||||
done()
|
||||
return ori() + " wrapper"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
mySystem.getSystem().dogeSelectors.wow(1)
|
||||
})
|
||||
|
||||
it("should provide the state as the first argument to the inner function", function(done){
|
||||
|
||||
// Given
|
||||
const mySystem = new System({
|
||||
state: {
|
||||
doge: {
|
||||
abc: "123"
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
{
|
||||
statePlugins: {
|
||||
doge: {
|
||||
selectors: {
|
||||
wow: () => (system) => {
|
||||
return "original"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
statePlugins: {
|
||||
doge: {
|
||||
wrapSelectors: {
|
||||
wow: (ori, system) => (dogeState) => {
|
||||
// Then
|
||||
expect(dogeState.toJS().abc).toEqual('123')
|
||||
done()
|
||||
return ori() + " wrapper"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
mySystem.getSystem().dogeSelectors.wow(1)
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user