当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript test.describe函数代码示例

本文整理汇总了TypeScript中test.describe函数的典型用法代码示例。如果您正苦于以下问题:TypeScript describe函数的具体用法?TypeScript describe怎么用?TypeScript describe使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了describe函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: describe

import { describe, it, assert } from "test";
import * as navigation from "common/util/navigation";

describe("navigation", () => {
  it("transformUrl", () => {
    assert.equal(navigation.transformUrl("about:blank"), "about:blank");
    assert.equal(navigation.transformUrl("https://itch.io"), "https://itch.io");
    assert.equal(navigation.transformUrl("itch.io"), "http://itch.io");
    assert.equal(
      navigation.transformUrl("http://localhost.com:8080/randomizer"),
      "http://localhost.com:8080/randomizer"
    );
    assert.equal(
      navigation.transformUrl("kermit plushie"),
      "https://duckduckgo.com/?q=kermit%20plushie&kae=d"
    );
    assert.equal(
      navigation.transformUrl("?kermit"),
      "https://duckduckgo.com/?q=kermit&kae=d"
    );
    assert.equal(
      navigation.transformUrl(""),
      "https://duckduckgo.com/?q=&kae=d"
    );
  });
});
开发者ID:itchio,项目名称:itch,代码行数:26,代码来源:navigation.spec.ts

示例2: describe

describe("Context", () => {
  it("Context propagates progress", async () => {
    const c = new Context(store);

    let p1 = 0;
    let p2 = 0;
    c.on("progress", info => {
      p1 = info.progress;
    });
    c.on("progress", info => {
      p2 = info.progress;
    });

    assert.equal(p1, 0);
    assert.equal(p2, 0);

    c.emitProgress({ progress: 0.5 });

    assert.equal(p1, 0.5);
    assert.equal(p2, 0.5);
  });

  it("Context returns result", async () => {
    const c = new Context(store);

    const ret = await (async () => {
      return c.withStopper({
        stop: async () => null,
        work: async () => 42,
      });
    })();

    assert.equal(ret, 42);
  });

  it("Context signals abort", async () => {
    const c = new Context(store);

    let abortCount = 0;
    let allowAbort = false;

    c.on("abort", () => {
      abortCount++;
    });

    assert.equal(abortCount, 0);
    assert.isFalse(c.isDead());

    let ranFirstTask = false;
    let cancelledFirstTask = false;
    let p1 = c
      .withStopper({
        stop: async () => {
          if (!allowAbort) {
            throw new Error("cannot cancel");
          }
        },
        work: async () => {
          ranFirstTask = true;
          await new ItchPromise(() => {
            /* just hang there */
          });
        },
      })
      .catch(() => {
        /* muffin */
      });

    await assert.isRejected(c.tryAbort());
    assert.equal(abortCount, 0);
    assert.isTrue(ranFirstTask);
    assert.isFalse(cancelledFirstTask);

    allowAbort = true;
    await c.tryAbort();
    assert.equal(abortCount, 1);
    assert.isTrue(c.isDead());
    await p1;

    let ranSecondTask = false;
    let cancelledSecondTask = false;
    let p2 = c
      .withStopper({
        stop: async () => null,
        work: () => {
          ranSecondTask = true;
          return Promise.resolve();
        },
      })
      .catch(e => {
        if (isCancelled(e)) {
          cancelledSecondTask = true;
        } else {
          throw e;
        }
      });

    assert.isFalse(ranSecondTask);
    await p2;
    assert.isTrue(cancelledSecondTask);
//.........这里部分代码省略.........
开发者ID:itchio,项目名称:itch,代码行数:101,代码来源:index.spec.ts

示例3: describe

describe("datetime", () => {
  it("seconds", () => {
    assert.deepEqual(formatDurationAsMessage(38), {
      id: "duration.seconds",
      values: { x: "38" },
    });
    assert.deepEqual(formatDurationAsMessage(123), {
      id: "duration.minutes",
      values: { x: "2" },
    });
    assert.deepEqual(formatDurationAsMessage(3800), { id: "duration.hour" });
    assert.deepEqual(formatDurationAsMessage(3600 * 4 + 120), {
      id: "duration.hours",
      values: { x: "4" },
    });
  });

  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
    );
  });

  it("getFormatter", () => {
    const f1 = getFormatter(DATE_FORMAT, "en-US");
    const f2 = getFormatter(DATE_FORMAT, "en-US");
    assert.strictEqual(f1, f2, "should re-use cached formatter");
  });
});
开发者ID:itchio,项目名称:itch,代码行数:38,代码来源:datetime.spec.ts

示例4: describe

import { describe, it, assert } from "test";

import { truncate } from "common/format/truncate";

describe("truncate", () => {
  it("truncate", () => {
    assert.equal(truncate("hello", { length: 10 }), "hello");
    assert.equal(truncate(null, { length: 10 }), null);
    assert.equal(
      truncate("hello my friend this is a Nigerian prince and I", {
        length: 10,
      }),
      "hello m..."
    );
  });
});
开发者ID:itchio,项目名称:itch,代码行数:16,代码来源:truncate.spec.ts

示例5: describe

describe("t", () => {
  it("formats a french string", () => {
    const i18n = {
      lang: "fr",
      strings: {
        fr: {
          "hello.there": "Bonjour, {name}",
        },
      },
      queued: null as any,
      downloading: null as any,
      locales: null as any,
    };
    assert.equal(t(i18n, ["hello.there", { name: "Brock" }]), "Bonjour, Brock");
  });
  it("falls back to english", () => {
    const i18n = {
      lang: "fr",
      strings: {
        en: {
          "hello.there": "Hi, {name}",
        },
      },
      queued: null as any,
      downloading: null as any,
      locales: null as any,
    };
    assert.equal(t(i18n, ["hello.there", { name: "Brock" }]), "Hi, Brock");
  });
  it("falls back to defaultValue", () => {
    const i18n = {
      lang: "en",
      strings: {
        en: {},
      },
      queued: null as any,
      downloading: null as any,
      locales: null as any,
    };
    assert.equal(
      t(i18n, ["hello.there", { name: "Brock", defaultValue: "Bye brock" }]),
      "Bye brock"
    );
  });
});
开发者ID:itchio,项目名称:itch,代码行数:45,代码来源:t.spec.ts

示例6: describe

describe("group-id-by", () => {
  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,代码行数:52,代码来源:group-id-by.spec.ts

示例7: describe

import { describe, it, assert } from "test";

import { fileSize } from "common/format/filesize";

describe("filesize", () => {
  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,代码行数:13,代码来源:filesize.spec.ts

示例8: describe

import { describe, it, assert } from "test";

import { formatPrice } from "./price";

describe("price", () => {
  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,代码行数:15,代码来源:price.spec.ts

示例9: describe

import { describe, it, assert } from "test";
import getByIds from "common/helpers/get-by-ids";

describe("get-by-ids", () => {
  it("gets records by IDs, being chill about null values", () => {
    const records = {
      "12": {
        word: "twelve",
      },
      "34": {
        word: "thirty-four",
      },
      "56": {
        word: "fifty-six",
      },
    };

    assert.deepEqual(getByIds(null, []), []);
    assert.deepEqual(getByIds(records, null), []);
    assert.deepEqual(getByIds(records, []), []);
    assert.deepEqual(getByIds(records, ["34"]), [{ word: "thirty-four" }]);
    assert.deepEqual(getByIds(records, ["56", "1024", "12"]), [
      { word: "fifty-six" },
      { word: "twelve" },
    ]);
  });
});
开发者ID:itchio,项目名称:itch,代码行数:27,代码来源:get-by-ids.spec.ts

示例10: describe

describe("camelify", () => {
  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");
  });

  it("camelifyObject", () => {
    assert.deepEqual(
      camelifyObject({
        heed: 12,
        the_call: {
          display_name: "waffles",
        },
        alreadyDone: ["dont_touch_me"],
      }),
      {
        heed: 12,
        theCall: {
          displayName: "waffles",
        },
        alreadyDone: ["dont_touch_me"],
      }
    );

    const date = new Date();
    assert.deepEqual(camelifyObject({ created_at: date }), {
      createdAt: date,
    });
  });
});
开发者ID:itchio,项目名称:itch,代码行数:33,代码来源:camelify.spec.ts


注:本文中的test.describe函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。