本文整理匯總了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)
);
});