本文整理汇总了TypeScript中redux-observable.ActionsObservable.of方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ActionsObservable.of方法的具体用法?TypeScript ActionsObservable.of怎么用?TypeScript ActionsObservable.of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redux-observable.ActionsObservable
的用法示例。
在下文中一共展示了ActionsObservable.of方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('fetch$ epic', () => {
const action$ = ActionsObservable.of({
type: TodoAction.Constants.FETCH_TODOS,
});
it('dispatches the correct actions when successful', async () => {
const mockResponse = mockData;
const mockService = {
fetchItems: () => Promise.resolve(mockResponse),
};
const expectedOutputActions = {
type: TodoAction.Constants.SET_TODOS,
payload: mockResponse,
};
const obs = fetch$(mockService)(action$);
await expect(obs.toPromise()).resolves.toEqual(expectedOutputActions);
});
it('dispatches an error when the call fails', async () => {
const mockService: Todo.Fetcher = {
fetchItems: () => Promise.reject('error'),
};
const expectedOutputActions = {
type: TodoAction.Constants.REQUEST_FAILED,
payload: 'Fetch Failed',
};
const obs = fetch$(mockService)(action$);
await expect(obs.toPromise()).resolves.toEqual(expectedOutputActions);
});
});
示例2: test
test("and allows continuing", async () => {
let registeredCallback;
ipc.once = (event, callback) => {
if (event === "show-message-box-response") {
registeredCallback = callback;
}
};
ipc.send = (event, data) => {
expect(event).toBe("show-message-box");
expect(data.message).toEqual(
"Unsaved data will be lost. Are you sure you want to quit?"
);
// "Yes"
registeredCallback("dummy-event", 0);
};
const state = buildState(true);
const responses = await closeNotebookEpic(
ActionsObservable.of(
actions.closeNotebook({ contentRef: "contentRef1" })
),
{ value: state }
)
.pipe(toArray())
.toPromise();
expect(responses).toEqual([
coreActions.killKernel({ kernelRef: "kernelRef1", restarting: false }),
actions.closeNotebookProgress({
newState: DESKTOP_NOTEBOOK_CLOSING_READY_TO_CLOSE
})
]);
});
示例3: test
test("returns an Observable with an initial state of idle", done => {
const action$ = ActionsObservable.of({
type: actionsModule.LAUNCH_KERNEL_SUCCESSFUL,
payload: {
kernel: {
channels: of({
header: { msg_type: "status" },
content: { execution_state: "idle" }
}) as Subject<any>,
cwd: "/home/tester",
type: "websocket"
},
kernelRef: "fakeKernelRef",
contentRef: "fakeContentRef",
selectNextKernel: false
}
});
const obs = watchExecutionStateEpic(action$);
obs.pipe(toArray()).subscribe(
// Every action that goes through should get stuck on an array
actions => {
const types = actions.map(({ type }) => type);
expect(types).toEqual([actionsModule.SET_EXECUTION_STATE]);
},
err => done.fail(err), // It should not error in the stream
() => done()
);
});
示例4: test
test("Informs about disconnected kernels, allows reconnection", async () => {
const state$ = {
value: {
core: stateModule.makeStateRecord({
kernelRef: "fake",
entities: stateModule.makeEntitiesRecord({
contents: stateModule.makeContentsRecord({
byRef: Immutable.Map({
fakeContent: stateModule.makeNotebookContentRecord()
})
}),
kernels: stateModule.makeKernelsRecord({
byRef: Immutable.Map({
fake: stateModule.makeRemoteKernelRecord({
channels: null,
status: "not connected"
})
})
})
})
}),
app: {
notificationSystem: { addNotification: jest.fn() }
}
}
};
const action$ = ActionsObservable.of(
actions.executeCell({ id: "first", contentRef: "fakeContentRef" })
);
const responses = await executeCellEpic(action$, state$)
.pipe(toArray())
.toPromise();
expect(responses).toEqual([]);
});
示例5: test
test("calls launchKernelObservable if given the correct action", async () => {
const action$ = ActionsObservable.of(
actionsModule.launchKernel({
kernelSpec: { spec: "hokey", name: "woohoo" },
contentRef: "abc",
cwd: "~",
selectNextKernel: true,
kernelRef: "123"
})
);
const state = {
core: makeStateRecord(),
app: {
kernel: null
}
};
const responses = await launchKernelEpic(action$, { value: state })
.pipe(toArray())
.toPromise();
expect(responses[0]).toEqual(
actionsModule.setKernelspecInfo({
kernelInfo: { spec: "hokey", name: "woohoo" },
contentRef: "abc"
})
);
expect(responses[1]).toEqual(
actionsModule.launchKernelSuccessful({
kernel: {
info: null,
lastActivity: null,
type: "zeromq",
cwd: "~",
hostRef: null,
channels: expect.anything(),
spawn: expect.anything(),
connectionFile: "connectionFile.json",
kernelSpecName: "woohoo",
status: "launched"
},
selectNextKernel: true,
contentRef: "abc",
kernelRef: "123"
})
);
expect(responses[2]).toEqual(
actionsModule.setExecutionState({
kernelStatus: "launched",
kernelRef: "123"
})
);
});
示例6: test
test("invokes a SAVE_CONFIG when the SET_CONFIG_AT_KEY action happens", done => {
const action$ = ActionsObservable.of({ type: "SET_CONFIG_AT_KEY" });
const responseActions = saveConfigOnChangeEpic(action$);
responseActions.subscribe(
x => {
expect(x).toEqual({ type: "SAVE_CONFIG" });
done();
},
err => done.fail(err)
);
});