Skip to content

Commit

Permalink
Fixing a bug with noMatchWarning #267
Browse files Browse the repository at this point in the history
  • Loading branch information
Krasimir Tsonev committed Jan 23, 2021
1 parent 4ebbd50 commit 6a1eca9
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 11 deletions.
4 changes: 3 additions & 1 deletion lib/es/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

import { pushStateAvailable, matchRoute, parseQuery, extractGETParameters, isFunction, isString, clean, parseNavigateOptions, windowAvailable, getCurrentEnvURL, accumulateHooks } from "./utils";
import Q from "./Q";
import setLocationPath from "./middlewares/setLocationPath";
Expand Down Expand Up @@ -86,7 +88,7 @@ export default function Navigo(appRoute, resolveOptions) {
instance: self,
currentLocationPath: to ? clean(root) + "/" + clean(to) : undefined,
navigateOptions: {},
resolveOptions: options || DEFAULT_RESOLVE_OPTIONS
resolveOptions: _extends({}, DEFAULT_RESOLVE_OPTIONS, options)
};
Q([setLocationPath, matchPathToRegisteredRoutes, Q["if"](function (_ref) {
var matches = _ref.matches;
Expand Down
4 changes: 3 additions & 1 deletion lib/navigo.amd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/navigo.amd.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/navigo.amd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/navigo.amd.min.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion lib/navigo.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/navigo.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/navigo.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/navigo.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "navigo",
"version": "8.7.1",
"version": "8.7.2",
"description": "A simple vanilla JavaScript router",
"main": "lib/navigo.js",
"browser": "lib/navigo.min.js",
Expand Down
15 changes: 15 additions & 0 deletions src/__tests__/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,21 @@ describe("Given the Navigo library", () => {
expect(warn).not.toBeCalled();
warn.mockRestore();
});
describe("and we set noMatchWarning=true in the navigo constructor", () => {
it("should not print a warning if there is no matching route", () => {
const warn = jest.spyOn(console, "warn");
warn.mockImplementationOnce(() => {});
const r: NavigoRouter = new Navigo("/", {
hash: true,
noMatchWarning: true,
});
const res = r.resolve("/", {});

expect(res).toEqual(false);
expect(warn).not.toBeCalled();
warn.mockRestore();
});
});
});
it("should still update the browser URL", () => {
const warn = jest.spyOn(console, "warn");
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default function Navigo(
instance: self,
currentLocationPath: to ? `${clean(root)}/${clean(to)}` : undefined,
navigateOptions: {},
resolveOptions: options || DEFAULT_RESOLVE_OPTIONS,
resolveOptions: { ...DEFAULT_RESOLVE_OPTIONS, ...options },
};
Q(
[
Expand Down

0 comments on commit 6a1eca9

Please sign in to comment.