Skip to content

Commit d3564aa

Browse files
test(action-chain): fix tests to run events sync
1 parent 79dc158 commit d3564aa

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

packages/node_modules/action-chain/src/ActionChain.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export type OperatorExecution = {
3636
}
3737

3838
export interface ActionChainEvents {
39-
provider: Execution & {
39+
effect: Execution & {
4040
name: string
4141
method: string | number | symbol
4242
result: any
@@ -77,7 +77,7 @@ export class ActionChain<Effects> extends EventEmitter<ActionChainEvents> {
7777
const result = target[prop](...args)
7878
if (result instanceof Promise) {
7979
result.then((promisedResult) => {
80-
instance.emitAsync('provider', {
80+
instance.emitAsync('effect', {
8181
...execution,
8282
name: path,
8383
method: prop,
@@ -86,7 +86,7 @@ export class ActionChain<Effects> extends EventEmitter<ActionChainEvents> {
8686
})
8787
})
8888
} else {
89-
instance.emitAsync('provider', {
89+
instance.emitAsync('effect', {
9090
...execution,
9191
name: path,
9292
method: prop,

packages/node_modules/action-chain/src/index.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ type Context = typeof context
7373

7474
const actionChain = new ActionChain<Context>(context)
7575

76+
// FORCE SYNC EVENTS
77+
actionChain.emitAsync = actionChain.emit.bind(actionChain)
78+
7679
const action: <InitialValue = void>() => InitialValue extends void
7780
? INoValueAction<Context, InitialValue>
7881
: IAction<Context, InitialValue> = () => {
@@ -124,14 +127,14 @@ describe('CONTEXT', () => {
124127
})
125128
})
126129

127-
describe('PROVIDER', () => {
130+
describe('EFFECTS', () => {
128131
test('should track execution of effects', () => {
129132
expect.assertions(2)
130133
const fn = action().test(({ foo }) => {
131134
expect(foo.bar()).toBe('baz')
132135
})
133136

134-
actionChain.once('provider', (task) => {
137+
actionChain.once('effect', (task) => {
135138
expect(task).toEqual({
136139
operatorId: 0,
137140
actionId: 0,
@@ -150,7 +153,7 @@ describe('PROVIDER', () => {
150153
expect(foo.nestedProvider.bar()).toBe('baz')
151154
})
152155

153-
actionChain.once('provider', (task) => {
156+
actionChain.once('effect', (task) => {
154157
expect(task).toEqual({
155158
operatorId: 0,
156159
actionId: 0,
@@ -169,7 +172,7 @@ describe('PROVIDER', () => {
169172
expect(test.foo()).toBe('bar')
170173
})
171174

172-
actionChain.once('provider', (task) => {
175+
actionChain.once('effect', (task) => {
173176
expect(task).toEqual({
174177
operatorId: 0,
175178
actionId: 0,

0 commit comments

Comments
 (0)