-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(get): add _get function * feat(get): add tests
- Loading branch information
Eunjae Lee
authored
Jul 23, 2020
1 parent
02b95c3
commit 3173c9b
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import AlgoliaAnalytics from "../insights"; | ||
|
||
describe("get", () => { | ||
let analyticsInstance; | ||
beforeEach(() => { | ||
analyticsInstance = new AlgoliaAnalytics({ requestFn: () => {} }); | ||
}); | ||
|
||
it("should get values from instance after init", () => { | ||
const callback = jest.fn(); | ||
analyticsInstance.init({ | ||
appId: "xxx", | ||
apiKey: "***", | ||
region: "us" | ||
}); | ||
analyticsInstance._get("_appId", callback); | ||
expect(callback).toHaveBeenCalledTimes(1); | ||
expect(callback).toHaveBeenCalledWith("xxx"); | ||
|
||
analyticsInstance._get("_apiKey", callback); | ||
expect(callback).toHaveBeenCalledTimes(2); | ||
expect(callback).toHaveBeenCalledWith("***"); | ||
|
||
analyticsInstance._get("_region", callback); | ||
expect(callback).toHaveBeenCalledTimes(3); | ||
expect(callback).toHaveBeenCalledWith("us"); | ||
|
||
analyticsInstance._get("_hasCredentials", callback); | ||
expect(callback).toHaveBeenCalledTimes(4); | ||
expect(callback).toHaveBeenCalledWith(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type GetCallback = (value: any) => void; | ||
|
||
export function get(key: string, callback: GetCallback) { | ||
callback(this[key]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters