diff --git a/__tests__/index.spec.js b/__tests__/index.spec.js index f8c540f..68eec47 100644 --- a/__tests__/index.spec.js +++ b/__tests__/index.spec.js @@ -13,4 +13,8 @@ describe("entry point", () => { it("should export setOptions", () => { expect(entry.setOptions).toBeDefined(); }); + + it("should export setRouter", () => { + expect(entry.setRouter).toBeDefined(); + }); }); diff --git a/__tests__/install.spec.js b/__tests__/install.spec.js index 3525665..7e93a05 100644 --- a/__tests__/install.spec.js +++ b/__tests__/install.spec.js @@ -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"; @@ -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" }); diff --git a/src/index.js b/src/index.js index c46442a..b4f5379 100644 --- a/src/index.js +++ b/src/index.js @@ -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"; @@ -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; diff --git a/src/install.js b/src/install.js index 739b103..8f0a4ac 100644 --- a/src/install.js +++ b/src/install.js @@ -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;