From 2ec5d94f715ca697cf62f7c0fc61e6a86c857a50 Mon Sep 17 00:00:00 2001 From: Paolo Viotti Date: Tue, 22 Jan 2019 10:45:50 +0000 Subject: [PATCH] add test for initialization without instrumentation key --- test/ReactAI.test.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/ReactAI.test.ts b/test/ReactAI.test.ts index f25c129..08b1134 100644 --- a/test/ReactAI.test.ts +++ b/test/ReactAI.test.ts @@ -1,21 +1,34 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -import ReactAI from "../src/ReactAI"; describe("ReactAI", () => { + + beforeEach(() => { + jest.resetModules(); + }); + + it("fails initialization without instrumentation key", () => { + const ReactAI = require('../src/ReactAI').default; + expect(() => ReactAI.initialize({ instrumentationKey: "" })).toThrow(); + expect(() => ReactAI.initialize({})).toThrow(); + }); + it("initializes correctly", () => { + const ReactAI = require('../src/ReactAI').default; ReactAI.initialize({ instrumentationKey: "my-i-key" }); expect(ReactAI.rootInstance).not.toBe(undefined); expect(ReactAI.rootInstance.config.instrumentationKey).toBe("my-i-key"); }); it("sets debug mode as expected", () => { + const ReactAI = require('../src/ReactAI').default; ReactAI.initialize({ instrumentationKey: "my-i-key", debug: true }); expect(ReactAI.isDebugMode).toBe(true); }); it("sets context correctly", () => { + const ReactAI = require('../src/ReactAI').default; ReactAI.initialize({ instrumentationKey: "my-i-key" }); ReactAI.setContext({ prop1: "value1", prop2: "value2" }); expect(ReactAI.context.prop1).toBe("value1"); @@ -23,6 +36,7 @@ describe("ReactAI", () => { }); it("resets context correctly", () => { + const ReactAI = require('../src/ReactAI').default; ReactAI.initialize({ instrumentationKey: "my-i-key" }); ReactAI.setContext({ prop3: "value3" }, true); expect(ReactAI.context.prop3).toBe("value3"); @@ -30,6 +44,7 @@ describe("ReactAI", () => { }); it("resets context on initialization", () => { + const ReactAI = require('../src/ReactAI').default; ReactAI.initialize({ instrumentationKey: "my-i-key", initialContext: { prop1: "value1" } }); expect(ReactAI.context.prop1).toBe("value1"); expect(ReactAI.context.prop2).toBe(undefined);