mirror of
https://github.com/vector-im/element-call.git
synced 2024-11-15 00:04:59 +08:00
feat: update tests using vitest
- replace jest references with vitest
This commit is contained in:
parent
2a9f6663c1
commit
9a5afb11f6
@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { vi } from "vitest";
|
||||
import { screen, render } from "@testing-library/react";
|
||||
import { Toast } from "../src/Toast";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
@ -35,7 +36,7 @@ test("Toast renders", () => {
|
||||
});
|
||||
|
||||
test("Toast dismisses when clicked", async () => {
|
||||
const onDismiss = jest.fn();
|
||||
const onDismiss = vi.fn();
|
||||
render(
|
||||
<Toast open={true} onDismiss={onDismiss}>
|
||||
Hello world!
|
||||
@ -47,13 +48,13 @@ test("Toast dismisses when clicked", async () => {
|
||||
|
||||
test("Toast dismisses itself after the specified timeout", async () => {
|
||||
withFakeTimers(() => {
|
||||
const onDismiss = jest.fn();
|
||||
const onDismiss = vi.fn();
|
||||
render(
|
||||
<Toast open={true} onDismiss={onDismiss} autoDismiss={2000}>
|
||||
Hello world!
|
||||
</Toast>,
|
||||
);
|
||||
jest.advanceTimersByTime(2000);
|
||||
vi.advanceTimersByTime(2000);
|
||||
expect(onDismiss).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { mocked } from "jest-mock";
|
||||
import { vi } from "vitest";
|
||||
|
||||
import { getRoomIdentifierFromUrl } from "../src/UrlParams";
|
||||
import { Config } from "../src/config/Config";
|
||||
@ -24,11 +24,11 @@ const ROOM_ID = "!d45f138fsd";
|
||||
const ORIGIN = "https://call.element.io";
|
||||
const HOMESERVER = "call.ems.host";
|
||||
|
||||
jest.mock("../src/config/Config");
|
||||
vi.mock("../src/config/Config");
|
||||
|
||||
describe("UrlParams", () => {
|
||||
beforeAll(() => {
|
||||
mocked(Config.defaultServerName).mockReturnValue("call.ems.host");
|
||||
vi.mocked(Config.defaultServerName).mockReturnValue("call.ems.host");
|
||||
});
|
||||
|
||||
describe("handles URL with /room/", () => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`Toast renders 1`] = `
|
||||
<button
|
||||
|
@ -1,18 +0,0 @@
|
||||
import { TextEncoder } from "util";
|
||||
import JSDOMEnvironment_, {
|
||||
TestEnvironment as TestEnvironment_,
|
||||
} from "jest-environment-jsdom";
|
||||
import { JestEnvironmentConfig, EnvironmentContext } from "@jest/environment";
|
||||
|
||||
// This is a patched version of jsdom that adds TextEncoder, as a workaround for
|
||||
// https://github.com/jsdom/jsdom/issues/2524
|
||||
// Once that issue is resolved, this custom environment file can be deleted
|
||||
export default class JSDOMEnvironment extends JSDOMEnvironment_ {
|
||||
constructor(config: JestEnvironmentConfig, context: EnvironmentContext) {
|
||||
super(config, context);
|
||||
this.global.TextEncoder ??= TextEncoder;
|
||||
}
|
||||
}
|
||||
|
||||
export const TestEnvironment =
|
||||
TestEnvironment_ === JSDOMEnvironment_ ? JSDOMEnvironment : TestEnvironment_;
|
@ -1 +1,3 @@
|
||||
module.exports = { loadOlm: jest.fn(async () => {}) };
|
||||
import { vi } from "vitest";
|
||||
|
||||
module.exports = { loadOlm: vi.fn(async () => {}) };
|
||||
|
@ -1 +1,3 @@
|
||||
module.exports = jest.fn();
|
||||
import { vi } from "vitest";
|
||||
|
||||
module.exports = vi.fn();
|
||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { Mocked, mocked } from "jest-mock";
|
||||
import { vi, Mocked } from "vitest";
|
||||
import { RoomState } from "matrix-js-sdk/src/models/room-state";
|
||||
import { PosthogAnalytics } from "../../src/analytics/PosthogAnalytics";
|
||||
import { checkForParallelCalls } from "../../src/room/checkForParallelCalls";
|
||||
@ -23,10 +23,10 @@ import { withFakeTimers } from "../utils";
|
||||
const withMockedPosthog = (
|
||||
continuation: (posthog: Mocked<PosthogAnalytics>) => void,
|
||||
) => {
|
||||
const posthog = mocked({
|
||||
trackEvent: jest.fn(),
|
||||
const posthog = vi.mocked({
|
||||
trackEvent: vi.fn(),
|
||||
} as unknown as PosthogAnalytics);
|
||||
const instanceSpy = jest
|
||||
const instanceSpy = vi
|
||||
.spyOn(PosthogAnalytics, "instance", "get")
|
||||
.mockReturnValue(posthog);
|
||||
try {
|
||||
|
@ -13,12 +13,13 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { vi } from "vitest";
|
||||
|
||||
export function withFakeTimers(continuation: () => void): void {
|
||||
jest.useFakeTimers();
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
continuation();
|
||||
} finally {
|
||||
jest.useRealTimers();
|
||||
vi.useRealTimers();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user