diff --git a/test/rule.test.mjs b/test/rule.test.mjs index 05c26ae..732f1e1 100644 --- a/test/rule.test.mjs +++ b/test/rule.test.mjs @@ -12,6 +12,11 @@ describe("Rule", () => { }); describe("constructor()", () => { + it("can be initialized without anything", () => { + const rule = new Rule(); + expect(rule.name).toBeUndefined(); + }) + it("can be initialized with priority, conditions, event, and name", () => { const condition = { all: [Object.assign({}, conditionBase)], diff --git a/test/types.test-d.mts b/test/types.test-d.mts index 69bb309..b05c671 100644 --- a/test/types.test-d.mts +++ b/test/types.test-d.mts @@ -87,6 +87,11 @@ describe("type tests", () => { const rule = new Rule(ruleProps); const ruleFromString: Rule = new Rule(JSON.stringify(ruleProps)); + it("name of rule is possibly undefined", () => { + const ruleWithoutInit = new Rule(); + expectTypeOf(ruleWithoutInit.name); + }) + it("returns the engine when adding a rule", () => { expectTypeOf(engine.addRule(rule)); }); diff --git a/types/index.d.ts b/types/index.d.ts index 596cedc..591c4d7 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -189,8 +189,8 @@ export interface RuleResult { } export class Rule implements RuleProperties { - constructor(ruleProps: RuleProperties | string); - name: string; + constructor(ruleProps?: RuleProperties | string); + name?: string; conditions: TopLevelCondition; event: Event; priority: number;