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


TypeScript test.assert類代碼示例

本文整理匯總了TypeScript中test.assert的典型用法代碼示例。如果您正苦於以下問題:TypeScript assert類的具體用法?TypeScript assert怎麽用?TypeScript assert使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了assert類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: it

 it("camelify", () => {
   assert.equal(camelify("underscore"), "underscore");
   assert.equal(camelify("under score"), "under score");
   assert.equal(camelify("under_score"), "underScore");
   assert.equal(camelify("heed_the_call"), "heedTheCall");
   assert.equal(camelify("_sorry"), "Sorry");
 });
開發者ID:itchio,項目名稱:itch,代碼行數:7,代碼來源:camelify.spec.ts

示例2: it

  it("Sub-context work", async () => {
    const c = new Context(store);

    let subRef: Context;
    let canAbort = false;
    c.withSub(async sub => {
      subRef = sub;
      await sub.withStopper({
        stop: async () => {
          if (!canAbort) {
            throw new Error("can't abort");
          }
        },
        work: async () => {
          await new ItchPromise(() => {
            /* muffin */
          });
        },
      });
    }).catch(() => {
      // woops
    });

    await assert.isRejected(c.tryAbort());
    canAbort = true;
    await c.tryAbort();
    await assert.isTrue(c.isDead());
    await assert.isTrue(subRef.isDead());
  });
開發者ID:itchio,項目名稱:itch,代碼行數:29,代碼來源:index.spec.ts

示例3: it

 it("fileSize", () => {
   assert.equal(fileSize(1023), "1023 B");
   assert.equal(fileSize(234090), "229 KiB");
   assert.equal(fileSize(6934028), "6.6 MiB");
   assert.equal(fileSize(239502889), "228 MiB");
   assert.equal(fileSize(2395028891), "2.2 GiB");
 });
開發者ID:itchio,項目名稱:itch,代碼行數:7,代碼來源:filesize.spec.ts

示例4: it

 it("truncate", () => {
   assert.equal(truncate("hello", { length: 10 }), "hello");
   assert.equal(
     truncate("hello my friend this is a Nigerian prince and I", {
       length: 10,
     }),
     "hello m..."
   );
 });
開發者ID:HorrerGames,項目名稱:itch,代碼行數:9,代碼來源:truncate.spec.ts

示例5: it

  it("formatDate", () => {
    const refString = "April 3, 1994, 11:47:21";

    assert.equal(formatDate(null, "en", DATE_FORMAT), "");
    assert.equal(formatDate(new Date("haha"), "en", DATE_FORMAT), "Ø");
    assert.equal(
      formatDate(new Date("1994-04-03 11:47:21 +0"), "en", DATE_FORMAT),
      refString
    );
    assert.equal(
      formatDate(new Date("1994-04-03 11:47:21 +0"), "en-US", DATE_FORMAT),
      refString
    );
  });
開發者ID:itchio,項目名稱:itch,代碼行數:14,代碼來源:datetime.spec.ts

示例6: it

  it("groupIdBy", () => {
    assert.deepEqual(groupIdBy(null, "gameId"), {});
    assert.deepEqual(groupIdBy(undefined, "gameId"), {});
    assert.deepEqual(groupIdBy([], "gameId"), {});
    assert.deepEqual(groupIdBy({}, "gameId"), {});

    const items = [
      { id: 1, gameId: 11 },
      { id: 4, gameId: 44 },
      { id: 7, gameId: 77 },
      { id: 77, gameId: 77 },
    ];

    assert.deepEqual(groupIdBy(items, "gameId"), {
      11: [1],
      44: [4],
      77: [7, 77],
    } as any);

    assert.deepEqual(
      groupIdBy<typeof items[0]>(items, o => String(o.gameId * 10)),
      {
        110: [1],
        440: [4],
        770: [7, 77],
      } as any
    );

    assert.deepEqual(groupIdBy(items, "id"), {
      1: [1],
      4: [4],
      7: [7],
      77: [77],
    } as any);

    const itemMap = indexBy(items, "id");

    assert.deepEqual(groupIdBy(itemMap, "gameId"), {
      11: [1],
      44: [4],
      77: [7, 77],
    } as any);

    assert.deepEqual(groupIdBy(itemMap, "id"), {
      1: [1],
      4: [4],
      7: [7],
      77: [77],
    } as any);
  });
開發者ID:itchio,項目名稱:itch,代碼行數:50,代碼來源:group-id-by.spec.ts

示例7: it

 it("price", () => {
   assert.equal(formatPrice("USD", 1500), "$15.00");
   assert.equal(formatPrice("CAD", 60), "CAD $0.60");
   assert.equal(formatPrice("AUD", 75.1), "AUD $0.75");
   assert.equal(formatPrice("GBP", 1000), "£10.00");
   assert.equal(formatPrice("EUR", 2000), "20.00 €");
   assert.equal(formatPrice("JPY", 1500), "¥1500.00");
   assert.equal(formatPrice("BLORGONS", 100), "$1.00");
 });
開發者ID:HorrerGames,項目名稱:itch,代碼行數:9,代碼來源:price.spec.ts


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