describe("lib/utils", () => {
  jest.useFakeTimers();

  let utils = require("./../../src/lib/utils");
  let ldClient = require("ldclient-js").default;

  const mockLdClient = (() => {
    ldClient.identify = jest.fn();
    ldClient.initialize = jest.fn().mockImplementation(() => ({
      on: (event, callback) => {
        setTimeout(() => {
          callback();
        }, 1000);
      }
    }));
  });
  mockLdClient();

  it("exports functions", () => {
    expect(utils["ldClientWrapper"]).toBeDefined();
    expect(utils["ldOverrideFlag"]).toBeDefined();
    expect(utils["getAllFeatureFlags"]).toBeDefined();
  });

  describe("ldClientWrapper", () => {
    const key = "my key";
    const user = { key: "my user" };
    const options = { baseUrl: "http://test" };

    describe("proxies to ldClient", () => {
      beforeEach(() => {
        // `ldClientWrapper` is a singleton, we need to reset the module cache with each test
        // to be able to properly assert each instance of `ldClientWrapper`
        jest.resetModules();
        utils = require("./../../src/lib/utils");
        ldClient = require("ldclient-js").default;
        mockLdClient();
      });

      it("initializes with key, user and default options parameter", () => {
        utils.ldClientWrapper(key, user);
        expect(ldClient.initialize).toBeCalledWith(key, user, {});
      });

      it("initializes with key, user and options", () => {
        utils.ldClientWrapper(key, user, options);
        expect(ldClient.initialize).toBeCalledWith(key, user, options);
      });
    });

    it("does not instantiate ldclient-js more than once", () => {
      utils.ldClientWrapper(key, user);
      utils.ldClientWrapper(key, user);
      utils.ldClientWrapper(key, user);
      expect(ldClient.initialize).toHaveBeenCalledTimes(1);
    });

    it("onReady calls wait for ready event to fire", () => {
      const callbackMock = jest.fn();
      utils.ldClientWrapper(key, user).onReady(callbackMock);
      utils.ldClientWrapper(key, user).onReady(callbackMock);
      utils.ldClientWrapper(key, user).onReady(callbackMock);
      expect(callbackMock.mock.instances.length).toBe(0);
    });

    it("executes all onReady calls after ldClient is ready", () => {
      const callbackMock = jest.fn();
      utils.ldClientWrapper(key, user).onReady(callbackMock);
      utils.ldClientWrapper(key, user).onReady(callbackMock);
      utils.ldClientWrapper(key, user).onReady(callbackMock);
      jest.runAllTimers();
      expect(callbackMock.mock.instances.length).toBe(3);
    });
  });

  describe("getAllFeatureFlags", () => {

  });

  describe("identify", () => {
    it("ldclient-js identify is called", () => {
      utils.identify(1234, {}).then( () => {
        expect(ldClient.identify).toHaveBeenCalled();
      });
    });
  });

  describe("track", () => {
    it("ldclient-js track is called", () => {
      utils.track(1234, {}).then( () => {
        expect(ldClient.track).toHaveBeenCalled();
      });
    });
  });

  describe("ldOverrideFlag", () => {

  });

  describe("feature", () => {
    it("ldclient-js feature is called", () => {
      utils.feature("home-test", {}).then( () => {
        expect(ldClient.variation).toHaveBeenCalled();
      });
    });
  });

});

@@ -209,24 +209,25 @@
  jest.fn();%0A
+%0A
     ldClient
@@ -385,16 +385,43 @@
 %0A      %7D
+,%0A      variation: () =%3E %7B%7D
 %0A    %7D))
@@ -3122,32 +3122,121 @@
 %3E %7B%0A    
-it(%22ldclient-js 
+const key = %22my key%22;%0A    const user = %7B key: %22my user%22 %7D;%0A    const featureFlag = %22home-test%22;%0A%0A    it(%22
 feature 
@@ -3238,32 +3238,38 @@
 ture is called%22,
+ async
  () =%3E %7B%0A      u
@@ -3271,86 +3271,117 @@
     
+const spy = jest.spyOn(
 utils
-.
+, %22
 feature
-(%22home-test%22, %7B%7D).then( () =%3E %7B%0A        expect(ldClient.variation
+%22);%0A      await utils.feature(key, user, featureFlag);%0A      expect(spy
 ).to
@@ -3394,34 +3394,24 @@
 enCalled();%0A
-      %7D);%0A
     %7D);%0A  %7D)

add test to ensure feature is called