-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresources.test.ts
43 lines (39 loc) · 1.15 KB
/
resources.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)
// SPDX-License-Identifier: Apache-2.0
import { expect, it } from "vitest";
import { destroyResources, Resource } from "./resources";
it("destroys all resources in the array", () => {
const events: string[] = [];
const resources: Resource[] = [
{
destroy() {
events.push("destroyed 1");
}
},
{
destroy() {
events.push("destroyed 2");
}
}
];
destroyResources(resources);
expect(events).toEqual(["destroyed 2", "destroyed 1"]); // reverse order
});
it("handles cycles correctly", () => {
const events: string[] = [];
const resources: Resource[] = [
{
destroy() {
events.push("destroyed 1");
destroyResources(resources); // still only destroys each resource only once
}
},
{
destroy() {
events.push("destroyed 2");
}
}
];
destroyResources(resources);
expect(events).toEqual(["destroyed 2", "destroyed 1"]);
});