mirror of
https://github.com/penpot/penpot.git
synced 2026-11-03 08:30:40 +00:00
23 lines
670 B
JavaScript
23 lines
670 B
JavaScript
import { describe, test, expect } from "vitest";
|
|
import { SafeGuard } from "./SafeGuard.js";
|
|
|
|
describe("SafeGuard", () => {
|
|
test("create a new SafeGuard", () => {
|
|
const safeGuard = new SafeGuard("Context");
|
|
expect(safeGuard.context).toBe("Context");
|
|
expect(safeGuard.elapsed).toBeLessThan(100);
|
|
});
|
|
|
|
test("SafeGuard throws an error when too much time is spent", () => {
|
|
expect(() => {
|
|
const safeGuard = new SafeGuard("Context", 100);
|
|
safeGuard.start();
|
|
// NOTE: This is the type of loop we try to
|
|
// be safe.
|
|
while (true) {
|
|
safeGuard.update();
|
|
}
|
|
}).toThrow('Safe guard timeout "Context"');
|
|
});
|
|
});
|