當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript state.State類代碼示例

本文整理匯總了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,
    });
  });
開發者ID:nusmodifications,項目名稱:nusmods,代碼行數:26,代碼來源:planner.test.ts

示例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]: [],
      },
//.........這裏部分代碼省略.........
開發者ID:nusmodifications,項目名稱:nusmods,代碼行數:101,代碼來源:planner.test.ts


注:本文中的types/state.State類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。