Skip to content

Commit

Permalink
chore: move tests to ts
Browse files Browse the repository at this point in the history
  • Loading branch information
dni committed Jan 3, 2024
1 parent cdce5aa commit cd2eaf7
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 9 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/Nav.spec.jsx → tests/Nav.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Router } from "@solidjs/router";
import { render, screen } from "@solidjs/testing-library";
import { describe, expect } from "vitest";
import { describe, expect, test } from "vitest";

import Nav from "../src/Nav";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fireEvent, render, screen } from "@solidjs/testing-library";
import { describe, expect, test } from "vitest";
import { describe, expect, test, vi } from "vitest";

import SelectAsset from "../../src/components/AssetSelect";
import { BTC, LBTC, LN, sideReceive, sideSend } from "../../src/consts";
Expand Down
2 changes: 1 addition & 1 deletion tests/components/ClickableAmount.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fireEvent, render } from "@solidjs/testing-library";
import { describe, expect, vitest } from "vitest";
import { describe, expect, test, vitest } from "vitest";

import ClickableAmount from "../../src/components/ClickableAmount";
import t from "../../src/i18n";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { render, screen } from "@solidjs/testing-library";
import { describe, expect, test } from "vitest";

import Error from "../../src/Error";
import i18n from "../../src/i18n/i18n";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render } from "@solidjs/testing-library";
import { beforeAll, beforeEach, expect, vi } from "vitest";
import { beforeAll, beforeEach, describe, expect, test, vi } from "vitest";

import Fees from "../../src/components/Fees";
import * as signals from "../../src/signals";
Expand All @@ -8,6 +8,7 @@ import { cfg } from "../config";

describe("Fees component", () => {
beforeAll(() => {
// @ts-ignore
signals.setConfig(cfg);
signals.setReverse(true);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { fireEvent, render } from "@solidjs/testing-library";
import { describe, expect, test } from "vitest";

import Reverse from "../../src/components/Reverse";
import { BTC, LN } from "../../src/config";
import { BTC, LN } from "../../src/consts";
import {
assetReceive,
assetSend,
Expand All @@ -16,7 +16,7 @@ describe("Reverse", () => {
setAssetSend(BTC);
setAssetReceive(LN);

expect(reverse()).toEqual(true);
expect(reverse()).toEqual(false);

const {
container: { firstChild: flip },
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/i18n/detect.spec.js → tests/i18n/detect.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect } from "vitest";
import { describe, expect, test } from "vitest";

import { defaultLanguage } from "../../src/config";
import { getNavigatorLanguage } from "../../src/i18n/detect";
Expand Down
2 changes: 1 addition & 1 deletion tests/i18n/i18n.spec.js → tests/i18n/i18n.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect } from "vitest";
import { describe, expect, test } from "vitest";

import { rawDict } from "../../src/i18n/i18n";

Expand Down
2 changes: 1 addition & 1 deletion tests/signals.spec.js → tests/signals.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from "vitest";
import { describe, expect, test } from "vitest";

import { BTC, LBTC, LN } from "../src/consts";
import {
Expand Down
7 changes: 7 additions & 0 deletions tests/utils/webln.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { detectWebLNProvider, enableWebln } from "../../src/utils/webln";
describe("WebLN", () => {
beforeEach(() => {
log.error = vitest.fn();
// @ts-ignore
window.webln = undefined;
});

Expand All @@ -24,29 +25,35 @@ describe("WebLN", () => {
});

test("should call WebLN callback if enable call succeeds", async () => {
// @ts-ignore
window.webln = {
enable: vitest.fn().mockResolvedValue(undefined),
} as any;
const cb = vitest.fn();

expect(await enableWebln(cb));

// @ts-ignore
expect(window.webln.enable).toHaveBeenCalledTimes(1);
// @ts-ignore
expect(window.webln.enable).toHaveBeenCalledWith();

expect(cb).toHaveBeenCalledTimes(1);
expect(log.error).toHaveBeenCalledTimes(0);
});

test("should not call WebLN callback if enable call fails", async () => {
// @ts-ignore
window.webln = {
enable: vitest.fn().mockRejectedValue("unauthorized"),
} as any;
const cb = vitest.fn();

expect(await enableWebln(cb));

// @ts-ignore
expect(window.webln.enable).toHaveBeenCalledTimes(1);
// @ts-ignore
expect(window.webln.enable).toHaveBeenCalledWith();

expect(cb).toHaveBeenCalledTimes(0);
Expand Down

0 comments on commit cd2eaf7

Please sign in to comment.