-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathevaluateFlags.test.ts
52 lines (44 loc) · 1.27 KB
/
evaluateFlags.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
44
45
46
47
48
49
50
51
52
import { evaluateFlags } from "./evaluateFlags";
import type { ClientFeaturesResponse } from "unleash-client";
describe("evaluateFlags", () => {
it("should return toggles when engine initializes successfully", () => {
const definitions: ClientFeaturesResponse = {
version: 1,
features: [
{ name: "featureA", enabled: true },
{ name: "featureB", enabled: false },
],
};
const result = evaluateFlags(definitions, {});
expect(result).toEqual({
toggles: [
{
name: "featureA",
enabled: true,
impressionData: false,
variant: {
enabled: false,
feature_enabled: true,
name: "disabled",
},
},
],
});
});
it("should return empty toggles when engine initialization fails", () => {
vi.spyOn(console, "error").mockImplementationOnce(() => {});
const definitions = {
message: "Invalid definitions",
};
const result = evaluateFlags(definitions as any, {});
expect(result).toEqual({
toggles: [],
});
expect(console.error).toHaveBeenCalledWith(
expect.stringContaining(
"Unleash: Failed to evaluate flags from provided definitions"
),
expect.anything()
);
});
});