Skip to content

Commit

Permalink
feat: set router (#247)
Browse files Browse the repository at this point in the history
Co-authored-by: Matteo Gabriele <[email protected]>
  • Loading branch information
kierans and MatteoGabriele committed Apr 14, 2021
1 parent 82d9c30 commit 40070b7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions __tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ describe("entry point", () => {
it("should export setOptions", () => {
expect(entry.setOptions).toBeDefined();
});

it("should export setRouter", () => {
expect(entry.setRouter).toBeDefined();
});
});
11 changes: 10 additions & 1 deletion __tests__/install.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getVue, getRouter, install, getOptions } from "@/install";
import { getVue, getRouter, install, getOptions, setRouter } from "@/install";
import bootstrap from "@/bootstrap";
import extend from "@/extend";

Expand All @@ -19,6 +19,15 @@ describe("install", () => {
expect(getRouter()).toEqual({ foo: "bar" });
});

it("should set VueRouter", () => {
const router = { foo: "bar" };

install();
setRouter(router);

expect(getRouter()).toEqual(router);
});

it("should return Vue", () => {
install({ foo: "bar" });
expect(getVue()).toEqual({ foo: "bar" });
Expand Down
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { setOptions as _setOptions, install } from "./install";
import {
setOptions as _setOptions,
install,
setRouter as _setRouter,
} from "./install";
import _bootstrap from "./bootstrap";
import api from "./api";

Expand All @@ -7,6 +11,7 @@ export { install };

export const bootstrap = _bootstrap;
export const setOptions = _setOptions;
export const setRouter = _setRouter;

// export api for usages outside Vuejs context
export const query = api.query;
Expand Down
1 change: 1 addition & 0 deletions src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const getOptions = () => options;
export const setOptions = (_options) => mergeDeep(options, _options);
export const getVue = () => Vue;
export const getRouter = () => Router;
export const setRouter = (_Router) => (Router = _Router);

export function install(_Vue, _options = {}, _Router) {
Vue = _Vue;
Expand Down

0 comments on commit 40070b7

Please sign in to comment.