Skip to content
This repository has been archived by the owner on May 22, 2019. It is now read-only.

Commit

Permalink
Merge pull request #36 from Azure/test-without-key
Browse files Browse the repository at this point in the history
add test for initialization without instrumentation key
  • Loading branch information
hiraldesai authored Jan 22, 2019
2 parents 910bc7c + 2ec5d94 commit 4524583
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion test/ReactAI.test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,50 @@
// 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");
expect(ReactAI.context.prop2).toBe("value2");
});

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");
expect(ReactAI.context.prop1).toBe(undefined);
});

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);
Expand Down

0 comments on commit 4524583

Please sign in to comment.