本文整理匯總了TypeScript中types/state.State類的典型用法代碼示例。如果您正苦於以下問題:TypeScript State類的具體用法?TypeScript State怎麽用?TypeScript State使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了State類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: test
test('should add semesters for empty years', () => {
const emptyYear = {
[1]: [],
[2]: [],
[3]: [],
[4]: [],
};
expect(getAcadYearModules(getState(defaultState))).toEqual({
'2018/2019': emptyYear,
});
expect(
getAcadYearModules(
getState({
...defaultState,
minYear: '2016/2017',
maxYear: '2018/2019',
}),
),
).toEqual({
'2016/2017': emptyYear,
'2017/2018': emptyYear,
'2018/2019': emptyYear,
});
});
示例2: describe
describe(getAcadYearModules, () => {
const getState = (planner: PlannerState): State =>
({
planner,
moduleBank: {
modules: {},
moduleCodes: {},
},
} as any);
const expectModuleCodes = (modules: ModuleCode[]) =>
modules.map((moduleCode) =>
// This lets us ignore conflicts
expect.objectContaining({ moduleCode }),
);
test('should add semesters for empty years', () => {
const emptyYear = {
[1]: [],
[2]: [],
[3]: [],
[4]: [],
};
expect(getAcadYearModules(getState(defaultState))).toEqual({
'2018/2019': emptyYear,
});
expect(
getAcadYearModules(
getState({
...defaultState,
minYear: '2016/2017',
maxYear: '2018/2019',
}),
),
).toEqual({
'2016/2017': emptyYear,
'2017/2018': emptyYear,
'2018/2019': emptyYear,
});
});
test('should map modules to years and semesters', () => {
expect(
getAcadYearModules(
getState({
...defaultState,
modules: {
CS1010S: ['2018/2019', 1, 0],
},
}),
),
).toEqual({
'2018/2019': {
[1]: expectModuleCodes(['CS1010S']),
[2]: [],
[3]: [],
[4]: [],
},
});
expect(
getAcadYearModules(
getState({
...defaultState,
modules: {
CS1010X: ['2018/2019', 3, 0],
},
}),
),
).toEqual({
'2018/2019': {
[1]: [],
[2]: [],
[3]: expectModuleCodes(['CS1010X']),
[4]: [],
},
});
});
test('should map modules in the correct order', () => {
expect(
getAcadYearModules(
getState({
...defaultState,
modules: {
CS1010S: ['2018/2019', 1, 1],
MA1521: ['2018/2019', 1, 0],
MA1101R: ['2018/2019', 1, 2],
},
}),
),
).toEqual({
'2018/2019': {
[1]: expectModuleCodes(['MA1521', 'CS1010S', 'MA1101R']),
[2]: [],
[3]: [],
[4]: [],
},
//.........這裏部分代碼省略.........