本文整理汇总了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]: [],
},
//.........这里部分代码省略.........