Skip to content

Commit

Permalink
test: add __TEST__
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed May 3, 2021
1 parent 72278d5 commit 0c7d80b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
testEnvironment: 'node',
globals: {
__DEV__: true,
__TEST__: true,
__BROWSER__: true,
},
coverageDirectory: 'coverage',
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function createReplacePlugin(
: // hard coded dev/prod builds
JSON.stringify(!isProduction),
// this is only used during tests
__TEST__: isBundlerESMBuild ? `(process.env.NODE_ENV === 'test')` : 'false',
__TEST__: 'false',
// If the build is expected to run directly in the browser (global / esm builds)
__BROWSER__: isBrowserBuild,
__FEATURE_PROD_DEVTOOLS__: isBundlerESMBuild
Expand Down
1 change: 1 addition & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Global compile-time constants
declare var __DEV__: boolean
declare var __TEST__: boolean
declare var __FEATURE_PROD_DEVTOOLS__: boolean
declare var __BROWSER__: boolean
declare var __CI__: boolean
12 changes: 12 additions & 0 deletions src/history/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,17 @@ export function createMemoryHistory(base: string = ''): RouterHistory {
get: () => queue[position],
})

if (__TEST__) {
// @ts-ignore: only for tests
routerHistory.changeURL = function (url: string) {
const from = this.location
queue.splice(position++ + 1, queue.length, url)
triggerListeners(this.location, from, {
direction: NavigationDirection.unknown,
delta: 0,
})
}
}

return routerHistory
}

0 comments on commit 0c7d80b

Please sign in to comment.