slint/api/node/__test__/window.spec.mts
Nigel Breslaw 942b737577
Some checks are pending
autofix.ci / format_fix (push) Waiting to run
autofix.ci / lint_typecheck (push) Waiting to run
autofix.ci / ci (push) Blocked by required conditions
Introduce Vitest for api/node tests (#10107)
Currently Ava is used to unit test the api/node project.
Vitest is already used elsewhere in the monorepo, integrates well with 
Vite, is fast and automatically handles tests written in Typescript. 
Replacing Ava would simplify how Typescript tests are performed.

This PR introduces Vitest to the project, sets it up to match Ava 
(isolated process for each test) and ports just the window.spec.mts 
file.

Later PR's will port the rest.
2025-11-18 17:41:34 +02:00

44 lines
1.2 KiB
TypeScript

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
import { test, expect } from "vitest";
import { private_api, Window } from "../dist/index.js";
test("Window constructor", () => {
let thrownError: any;
try {
new private_api.Window();
} catch (error) {
thrownError = error;
}
expect(thrownError).toBeDefined();
expect(thrownError.code).toBe("GenericFailure");
expect(thrownError.message).toBe(
"Window can only be created by using a Component.",
);
});
test("Window show / hide", () => {
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
export component App inherits Window {
width: 300px;
height: 300px;
}`,
"",
);
expect(definition.App).not.toBeNull();
const instance = definition.App!.create();
expect(instance).not.toBeNull();
const window = instance!.window();
expect(window.visible).toBe(false);
window.show();
expect(window.visible).toBe(true);
window.hide();
expect(window.visible).toBe(false);
});