diff --git a/definitions/npm/history_v4.9.x/flow_v0.104.x-/history_v4.9.x.js b/definitions/npm/history_v4.9.x/flow_v0.104.x-v0.200.x/history_v4.9.x.js similarity index 100% rename from definitions/npm/history_v4.9.x/flow_v0.104.x-/history_v4.9.x.js rename to definitions/npm/history_v4.9.x/flow_v0.104.x-v0.200.x/history_v4.9.x.js diff --git a/definitions/npm/history_v4.9.x/flow_v0.104.x-/test_history_v4.9.x.js b/definitions/npm/history_v4.9.x/flow_v0.104.x-v0.200.x/test_history_v4.9.x.js similarity index 100% rename from definitions/npm/history_v4.9.x/flow_v0.104.x-/test_history_v4.9.x.js rename to definitions/npm/history_v4.9.x/flow_v0.104.x-v0.200.x/test_history_v4.9.x.js diff --git a/definitions/npm/history_v4.9.x/flow_v0.201.x-/history_v4.9.x.js b/definitions/npm/history_v4.9.x/flow_v0.201.x-/history_v4.9.x.js new file mode 100644 index 0000000000..561794a04a --- /dev/null +++ b/definitions/npm/history_v4.9.x/flow_v0.201.x-/history_v4.9.x.js @@ -0,0 +1,138 @@ +declare module 'history' { + declare function Unblock(): void; + + declare export type Action = 'PUSH' | 'REPLACE' | 'POP'; + + declare export type BrowserLocation = { + pathname: string, + search: string, + hash: string, + // Browser and Memory specific + state: {...}, + key: string, + ... + }; + + declare interface IBrowserHistory { + length: number; + location: BrowserLocation; + action: Action; + push(path: string, state?: {...}): void; + push(location: Partial): void; + replace(path: string, state?: {...}): void; + replace(location: Partial): void; + go(n: number): void; + goBack(): void; + goForward(): void; + listen((location: BrowserLocation, action: Action) => void): void; + block(message: string): typeof Unblock; + block( + (location: BrowserLocation, action: Action) => string + ): typeof Unblock; + } + + declare export type BrowserHistory = IBrowserHistory; + + declare type BrowserHistoryOpts = { + basename?: string, + forceRefresh?: boolean, + getUserConfirmation?: ( + message: string, + callback: (willContinue: boolean) => void + ) => void, + ... + }; + + declare function createBrowserHistory( + opts?: BrowserHistoryOpts + ): BrowserHistory; + + declare export type MemoryLocation = { + pathname: string, + search: string, + hash: string, + // Browser and Memory specific + state: {...}, + key: string, + ... + }; + + declare interface IMemoryHistory { + length: number; + location: MemoryLocation; + action: Action; + index: number; + entries: Array; + push(path: string, state?: {...}): void; + push(location: Partial): void; + replace(path: string, state?: {...}): void; + replace(location: Partial): void; + go(n: number): void; + goBack(): void; + goForward(): void; + // Memory only + canGo(n: number): boolean; + listen((location: MemoryLocation, action: Action) => void): void; + block(message: string): typeof Unblock; + block((location: MemoryLocation, action: Action) => string): typeof Unblock; + } + + declare export type MemoryHistory = IMemoryHistory; + + declare type MemoryHistoryOpts = { + initialEntries?: Array, + initialIndex?: number, + keyLength?: number, + getUserConfirmation?: ( + message: string, + callback: (willContinue: boolean) => void + ) => void, + ... + }; + + declare function createMemoryHistory(opts?: MemoryHistoryOpts): MemoryHistory; + + declare export type HashLocation = { + pathname: string, + search: string, + hash: string, + ... + }; + + declare interface IHashHistory { + length: number; + location: HashLocation; + action: Action; + push(path: string, state?: {...}): void; + push(location: Partial): void; + replace(path: string, state?: {...}): void; + replace(location: Partial): void; + go(n: number): void; + goBack(): void; + goForward(): void; + listen((location: HashLocation, action: Action) => void): void; + block(message: string): typeof Unblock; + block((location: HashLocation, action: Action) => string): typeof Unblock; + push(path: string): void; + } + + declare export type HashHistory = IHashHistory; + + declare type HashHistoryOpts = { + basename?: string, + hashType: 'slash' | 'noslash' | 'hashbang', + getUserConfirmation?: ( + message: string, + callback: (willContinue: boolean) => void + ) => void, + ... + }; + + declare function createHashHistory(opts?: HashHistoryOpts): HashHistory; + + declare function parsePath(path: string): BrowserLocation | MemoryLocation | HashLocation; + + declare function createPath( + path: BrowserLocation | MemoryLocation | HashLocation + ): string; +} diff --git a/definitions/npm/history_v4.9.x/flow_v0.201.x-/test_history_v4.9.x.js b/definitions/npm/history_v4.9.x/flow_v0.201.x-/test_history_v4.9.x.js new file mode 100644 index 0000000000..b95a7adbd9 --- /dev/null +++ b/definitions/npm/history_v4.9.x/flow_v0.201.x-/test_history_v4.9.x.js @@ -0,0 +1,295 @@ +// @flow + +import { describe, it } from 'flow-typed-test'; + +import {createBrowserHistory} from 'history'; +import {createMemoryHistory} from 'history'; +import {createHashHistory} from 'history'; +import {createPath} from 'history'; +import {parsePath} from 'history'; + +// browser history + +describe('browser history', () => { + it('should allow to get location fields', () => { + const history = createBrowserHistory({ + basename: "", + forceRefresh: false, + keyLength: 6, + }) + + const pathname: string = history.location.pathname + }); + + it('should allow to get browser and memory specific location fields', () => { + const history = createBrowserHistory({ + basename: "", + forceRefresh: false, + keyLength: 6, + }) + + const key: string = history.location.key + const state: {...} = history.location.state + }); + + it('should not allow to get field which is absent in the history', () => { + const history = createBrowserHistory({ + basename: "", + forceRefresh: false, + keyLength: 6, + }) + + // $FlowExpectedError[prop-missing] + history.foo + }); + + describe('#push', () => { + it('should allow to use string as first argument', () => { + const history = createBrowserHistory({ + basename: "", + forceRefresh: false, + keyLength: 6, + }) + + history.push("/") + }); + + it('should allow to use partial location as first argument', () => { + const history = createBrowserHistory({ + basename: "", + forceRefresh: false, + keyLength: 6, + }) + + history.push({ + pathname: "/", + state: { a: 1 }, + }) + }); + }); + + describe('#replace', () => { + it('should allow to use string as first argument', () => { + const history = createBrowserHistory({ + basename: "", + forceRefresh: false, + keyLength: 6, + }) + + history.replace("/") + }); + + it('should allow to use partial location as first argument', () => { + const history = createBrowserHistory({ + basename: "", + forceRefresh: false, + keyLength: 6, + }) + + history.replace({ + pathname: "/", + state: { a: 1 }, + }) + }); + }); +}); + +describe('memory history', () => { + it('should allow to get location fields', () => { + const history = createMemoryHistory({ + initialEntries: ["/"], + initialIndex: 0, + keyLength: 6, + }) + + const pathname: string = history.location.pathname + }); + + it('should allow to get browser and memory specific location fields', () => { + const history = createMemoryHistory({ + initialEntries: ["/"], + initialIndex: 0, + keyLength: 6, + }) + + const key: string = history.location.key + const state: {...} = history.location.state + }); + + it('should not allow to get field which is absent in the history', () => { + const history = createMemoryHistory({ + initialEntries: ["/"], + initialIndex: 0, + keyLength: 6, + }) + + // $FlowExpectedError[prop-missing] + history.foo + }); + + describe('#push', () => { + it('should allow to use string as first argument', () => { + const history = createMemoryHistory({ + initialEntries: ["/"], + initialIndex: 0, + keyLength: 6, + }) + + history.push("/") + }); + + it('should allow to use partial location as first argument', () => { + const history = createMemoryHistory({ + initialEntries: ["/"], + initialIndex: 0, + keyLength: 6, + }) + + history.push({ + pathname: "/", + state: { a: 1 }, + }) + }); + }); + + describe('#replace', () => { + it('should allow to use string as first argument', () => { + const history = createMemoryHistory({ + initialEntries: ["/"], + initialIndex: 0, + keyLength: 6, + }) + + history.replace("/") + }); + + it('should allow to use partial location as first argument', () => { + const history = createMemoryHistory({ + initialEntries: ["/"], + initialIndex: 0, + keyLength: 6, + }) + + history.replace({ + pathname: "/", + state: { a: 1 }, + }) + }); + }); +}); + +describe('hash history', () => { + it('should allow to get location fields', () => { + const history = createHashHistory({ + basename: "", + hashType: "slash", + }) + + const pathname: string = history.location.pathname + }); + + it('should not allow to get browser and memory specific location fields', () => { + const history = createHashHistory({ + basename: "", + hashType: "slash", + }) + + // $FlowExpectedError[prop-missing] + const key: string = history.location.key + // $FlowExpectedError[prop-missing] + const state: {...} = history.location.state + }); + + it('should not allow to get field which is absent in the history', () => { + const history = createHashHistory({ + basename: "", + hashType: "slash", + }) + + // $FlowExpectedError[prop-missing] + history.foo + }); + + + describe('#push', () => { + it('should allow to use string as first argument', () => { + const history = createHashHistory({ + basename: "", + hashType: "slash", + }) + + history.push("/") + }); + + it('should allow to use partial location as first argument', () => { + const history = createHashHistory({ + basename: "", + hashType: "slash", + }) + + history.push({ + search: "?a=1", + }) + }); + }); + + describe('#replace', () => { + it('should allow to use string as first argument', () => { + const history = createHashHistory({ + basename: "", + hashType: "slash", + }) + + history.replace("/") + }); + + it('should allow to use partial location as first argument', () => { + const history = createHashHistory({ + basename: "", + hashType: "slash", + }) + + history.push({ + search: "?a=1", + }) + }); + }); +}); + +describe('create path', () => { + it('should allow to use Location argument', () => { + const path = createPath({ + pathname: '/test', + search: '?a=1', + hash: 'slug', + }) + + const key: string = path + // $FlowExpectedError[incompatible-type] + const state: {...} = path + }); + + it('should not allow to accept void', () => { + // $FlowExpectedError[incompatible-call] + const path = createPath() + + const key: string = path + }); +}); + +describe('parse path', () => { + it('should allow to use string argument', () => { + const location = parsePath('/test?query#hash') + + const state: {...} = location + // $FlowExpectedError[incompatible-type] + const key: string = location + }); + + it('should not allow to accept void', () => { + // $FlowExpectedError[incompatible-call] + const location = parsePath() + + const state: {...} = location + }); +}); diff --git a/definitions/npm/history_v4.x.x/flow_v0.104.x-/history_v4.x.x.js b/definitions/npm/history_v4.x.x/flow_v0.104.x-v0.200.x/history_v4.x.x.js similarity index 100% rename from definitions/npm/history_v4.x.x/flow_v0.104.x-/history_v4.x.x.js rename to definitions/npm/history_v4.x.x/flow_v0.104.x-v0.200.x/history_v4.x.x.js diff --git a/definitions/npm/history_v4.x.x/flow_v0.104.x-/test_history_v4.x.x.js b/definitions/npm/history_v4.x.x/flow_v0.104.x-v0.200.x/test_history_v4.x.x.js similarity index 99% rename from definitions/npm/history_v4.x.x/flow_v0.104.x-/test_history_v4.x.x.js rename to definitions/npm/history_v4.x.x/flow_v0.104.x-v0.200.x/test_history_v4.x.x.js index 944f84f784..0a846f0f21 100644 --- a/definitions/npm/history_v4.x.x/flow_v0.104.x-/test_history_v4.x.x.js +++ b/definitions/npm/history_v4.x.x/flow_v0.104.x-v0.200.x/test_history_v4.x.x.js @@ -273,7 +273,7 @@ describe('create path', () => { }); it('should not allow to accept void', () => { - // $FlowExpectedError[incompatible-shape] + // $FlowExpectedError[incompatible-call] const path = createPath(); const key: string = path; diff --git a/definitions/npm/history_v4.x.x/flow_v0.201.x-/history_v4.x.x.js b/definitions/npm/history_v4.x.x/flow_v0.201.x-/history_v4.x.x.js new file mode 100644 index 0000000000..006e23bc62 --- /dev/null +++ b/definitions/npm/history_v4.x.x/flow_v0.201.x-/history_v4.x.x.js @@ -0,0 +1,106 @@ +declare module 'history' { + declare type Unregister = () => void; + + declare export type Action = 'PUSH' | 'REPLACE' | 'POP'; + + declare export type Location = {| + pathname: string, + search: string, + hash: string, + state: { ... }, + key: string, + |}; + + declare type History = {| + length: number, + location: HistoryLocation, + action: Action, + push: ((path: string, state?: { ... }) => void) & + ((location: Partial) => void), + replace: ((path: string, state?: { ... }) => void) & + ((location: Partial) => void), + go(n: number): void, + goBack(): void, + goForward(): void, + listen((location: HistoryLocation, action: Action) => void): Unregister, + block( + prompt: + | string + | boolean + | ((location: HistoryLocation, action: Action) => string | false | void) + ): Unregister, + createHref(location: Partial): string, + |}; + + declare export type BrowserHistory = History<>; + + declare type BrowserHistoryOpts = {| + basename?: string, + forceRefresh?: boolean, + getUserConfirmation?: ( + message: string, + callback: (willContinue: boolean) => void + ) => void, + keyLength?: number, + |}; + + declare function createBrowserHistory( + opts?: BrowserHistoryOpts + ): BrowserHistory; + + declare export type MemoryHistory = {| + ...History<>, + index: number, + entries: Array, + canGo(n: number): boolean, + |}; + + declare type MemoryHistoryOpts = {| + initialEntries?: Array, + initialIndex?: number, + keyLength?: number, + getUserConfirmation?: ( + message: string, + callback: (willContinue: boolean) => void + ) => void, + |}; + + declare function createMemoryHistory(opts?: MemoryHistoryOpts): MemoryHistory; + + declare export type HashLocation = {| + ...Location, + state: void, + key: void, + |}; + + declare export type HashHistory = History; + + declare type HashHistoryOpts = {| + basename?: string, + hashType: 'slash' | 'noslash' | 'hashbang', + getUserConfirmation?: ( + message: string, + callback: (willContinue: boolean) => void + ) => void, + |}; + + declare function createHashHistory(opts?: HashHistoryOpts): HashHistory; + + // PathUtils + declare function parsePath(path: string): Location; + + declare function createPath(location: Partial): string; + + // LocationUtils + declare function locationsAreEqual( + a: Partial, + b: Partial + ): boolean; + + declare function createLocation( + path: string | Partial, + state?: { ... }, + key?: string, + currentLocation?: Location + ): Location; +} diff --git a/definitions/npm/history_v4.x.x/flow_v0.201.x-/test_history_v4.x.x.js b/definitions/npm/history_v4.x.x/flow_v0.201.x-/test_history_v4.x.x.js new file mode 100644 index 0000000000..0a846f0f21 --- /dev/null +++ b/definitions/npm/history_v4.x.x/flow_v0.201.x-/test_history_v4.x.x.js @@ -0,0 +1,333 @@ +// @flow + +import { describe, it } from 'flow-typed-test'; + +import { + createBrowserHistory, + createMemoryHistory, + createHashHistory, + createPath, + parsePath, + locationsAreEqual, + createLocation, +} from 'history'; + +// browser history + +describe('browser history', () => { + it('should allow to get location fields', () => { + const history = createBrowserHistory({ + basename: '', + forceRefresh: false, + keyLength: 6, + }); + + const pathname: string = history.location.pathname; + }); + + it('should allow to get browser and memory specific location fields', () => { + const history = createBrowserHistory({ + basename: '', + forceRefresh: false, + keyLength: 6, + }); + + const key: string = history.location.key; + const state: { ... } = history.location.state; + }); + + it('should not allow to get field which is absent in the history', () => { + const history = createBrowserHistory({ + basename: '', + forceRefresh: false, + keyLength: 6, + }); + + // $FlowExpectedError[prop-missing] + history.foo; + }); + + describe('#push', () => { + it('should allow to use string as first argument', () => { + const history = createBrowserHistory({ + basename: '', + forceRefresh: false, + keyLength: 6, + }); + + history.push('/'); + }); + + it('should allow to use partial location as first argument', () => { + const history = createBrowserHistory({ + basename: '', + forceRefresh: false, + keyLength: 6, + }); + + history.push({ + pathname: '/', + state: { a: 1 }, + }); + }); + }); + + describe('#replace', () => { + it('should allow to use string as first argument', () => { + const history = createBrowserHistory({ + basename: '', + forceRefresh: false, + keyLength: 6, + }); + + history.replace('/'); + }); + + it('should allow to use partial location as first argument', () => { + const history = createBrowserHistory({ + basename: '', + forceRefresh: false, + keyLength: 6, + }); + + history.replace({ + pathname: '/', + state: { a: 1 }, + }); + }); + }); +}); + +describe('memory history', () => { + it('should allow to get location fields', () => { + const history = createMemoryHistory({ + initialEntries: ['/'], + initialIndex: 0, + keyLength: 6, + }); + + const pathname: string = history.location.pathname; + }); + + it('should allow to get browser and memory specific location fields', () => { + const history = createMemoryHistory({ + initialEntries: ['/'], + initialIndex: 0, + keyLength: 6, + }); + + const key: string = history.location.key; + const state: { ... } = history.location.state; + }); + + it('should not allow to get field which is absent in the history', () => { + const history = createMemoryHistory({ + initialEntries: ['/'], + initialIndex: 0, + keyLength: 6, + }); + + // $FlowExpectedError[prop-missing] + history.foo; + }); + + describe('#push', () => { + it('should allow to use string as first argument', () => { + const history = createMemoryHistory({ + initialEntries: ['/'], + initialIndex: 0, + keyLength: 6, + }); + + history.push('/'); + }); + + it('should allow to use partial location as first argument', () => { + const history = createMemoryHistory({ + initialEntries: ['/'], + initialIndex: 0, + keyLength: 6, + }); + + history.push({ + pathname: '/', + state: { a: 1 }, + }); + }); + }); + + describe('#replace', () => { + it('should allow to use string as first argument', () => { + const history = createMemoryHistory({ + initialEntries: ['/'], + initialIndex: 0, + keyLength: 6, + }); + + history.replace('/'); + }); + + it('should allow to use partial location as first argument', () => { + const history = createMemoryHistory({ + initialEntries: ['/'], + initialIndex: 0, + keyLength: 6, + }); + + history.replace({ + pathname: '/', + state: { a: 1 }, + }); + }); + }); +}); + +describe('hash history', () => { + it('should allow to get location fields', () => { + const history = createHashHistory({ + basename: '', + hashType: 'slash', + }); + + const pathname: string = history.location.pathname; + }); + + it('should not allow to get browser and memory specific location fields', () => { + const history = createHashHistory({ + basename: '', + hashType: 'slash', + }); + + // $FlowExpectedError[incompatible-type] + const key: string = history.location.key; + // $FlowExpectedError[incompatible-type] + const state: { ... } = history.location.state; + }); + + it('should not allow to get field which is absent in the history', () => { + const history = createHashHistory({ + basename: '', + hashType: 'slash', + }); + + // $FlowExpectedError[prop-missing] + history.foo; + }); + + describe('#push', () => { + it('should allow to use string as first argument', () => { + const history = createHashHistory({ + basename: '', + hashType: 'slash', + }); + + history.push('/'); + }); + + it('should allow to use partial location as first argument', () => { + const history = createHashHistory({ + basename: '', + hashType: 'slash', + }); + + history.push({ + search: '?a=1', + }); + }); + }); + + describe('#replace', () => { + it('should allow to use string as first argument', () => { + const history = createHashHistory({ + basename: '', + hashType: 'slash', + }); + + history.replace('/'); + }); + + it('should allow to use partial location as first argument', () => { + const history = createHashHistory({ + basename: '', + hashType: 'slash', + }); + + history.push({ + search: '?a=1', + }); + }); + }); +}); + +describe('create path', () => { + it('should allow to use Location argument', () => { + const path = createPath({ + pathname: '/test', + search: '?a=1', + hash: 'slug', + }); + + const key: string = path; + // $FlowExpectedError[incompatible-type] + const state: { ... } = path; + }); + + it('should not allow to accept void', () => { + // $FlowExpectedError[incompatible-call] + const path = createPath(); + + const key: string = path; + }); +}); + +describe('parse path', () => { + it('should allow to use string argument', () => { + const location = parsePath('/test?query#hash'); + + const state: { ... } = location; + // $FlowExpectedError[incompatible-type] + const key: string = location; + }); + + it('should not allow to accept void', () => { + // $FlowExpectedError[incompatible-call] + const location = parsePath(); + + const state: { ... } = location; + }); +}); + +describe('create location', () => { + it('should allow to use string argument', () => { + const location = createLocation('/test?query#hash'); + + const state: { ... } = location; + // $FlowExpectedError[incompatible-type] + const key: string = location; + }); + + it('should allow to use partial location as first argument', () => { + const location = createLocation({ + pathname: '/test', + search: '?a=1', + hash: 'slug', + }); + + const state: { ... } = location; + // $FlowExpectedError[incompatible-type] + const key: string = location; + }); +}); + +describe('locations are equal', () => { + it('should allow to use partial location as arguments and return boolean', () => { + const isEqual = locationsAreEqual( + { pathname: '/test' }, + { pathname: '/test', search: '?a=1' } + ); + + const bool: boolean = isEqual; + // $FlowExpectedError[incompatible-type] + const str: string = isEqual; + }); +}); diff --git a/definitions/npm/history_v5.x.x/flow_v0.104.x-/history_v5.x.x.js b/definitions/npm/history_v5.x.x/flow_v0.104.x-v0.200.x/history_v5.x.x.js similarity index 100% rename from definitions/npm/history_v5.x.x/flow_v0.104.x-/history_v5.x.x.js rename to definitions/npm/history_v5.x.x/flow_v0.104.x-v0.200.x/history_v5.x.x.js diff --git a/definitions/npm/history_v5.x.x/flow_v0.104.x-/test_history_v5.x.x.js b/definitions/npm/history_v5.x.x/flow_v0.104.x-v0.200.x/test_history_v5.x.x.js similarity index 100% rename from definitions/npm/history_v5.x.x/flow_v0.104.x-/test_history_v5.x.x.js rename to definitions/npm/history_v5.x.x/flow_v0.104.x-v0.200.x/test_history_v5.x.x.js diff --git a/definitions/npm/history_v5.x.x/flow_v0.201.x-/history_v5.x.x.js b/definitions/npm/history_v5.x.x/flow_v0.201.x-/history_v5.x.x.js new file mode 100644 index 0000000000..9c6b9b9fd9 --- /dev/null +++ b/definitions/npm/history_v5.x.x/flow_v0.201.x-/history_v5.x.x.js @@ -0,0 +1,92 @@ +declare module 'history' { + declare type Unregister = () => void; + + declare export type Action = 'PUSH' | 'REPLACE' | 'POP'; + + declare export type Location = {| + pathname: string, + search: string, + hash: string, + state: { ... }, + key: string, + |}; + + declare type History = {| + length: number, + location: HistoryLocation, + action: Action, + push: ((path: string, state?: { ... }) => void) & + ((location: Partial) => void), + replace: ((path: string, state?: { ... }) => void) & + ((location: Partial) => void), + go(n: number): void, + back(): void, + forward(): void, + listen(({| location: HistoryLocation, action: Action |}) => void): Unregister, + block( + blocker: (transition: {| + action: Action, + location: HistoryLocation, + retry: () => void, + |}) => void, + ): Unregister, + createHref(location: Partial): string, + |}; + + declare export type BrowserHistory = History<>; + + declare type BrowserHistoryOpts = {| + basename?: string, + forceRefresh?: boolean, + |}; + + declare function createBrowserHistory( + opts?: BrowserHistoryOpts + ): BrowserHistory; + + declare export type MemoryHistory = {| + ...History<>, + index: number, + entries: Array, + canGo(n: number): boolean, + |}; + + declare type MemoryHistoryOpts = {| + initialEntries?: Array, + initialIndex?: number, + |}; + + declare function createMemoryHistory(opts?: MemoryHistoryOpts): MemoryHistory; + + declare export type HashLocation = {| + ...Location, + state: void, + key: void, + |}; + + declare export type HashHistory = History; + + declare type HashHistoryOpts = {| + basename?: string, + |}; + + declare function createHashHistory(opts?: HashHistoryOpts): HashHistory; + + // PathUtils + declare function parsePath(path: string): Location; + + declare function createPath(location: Partial): string; + + // LocationUtils + declare function locationsAreEqual( + a: Partial, + b: Partial + ): boolean; + + declare function createLocation( + path: string | Partial, + state?: { ... }, + key?: string, + currentLocation?: Location + ): Location; +} diff --git a/definitions/npm/history_v5.x.x/flow_v0.201.x-/test_history_v5.x.x.js b/definitions/npm/history_v5.x.x/flow_v0.201.x-/test_history_v5.x.x.js new file mode 100644 index 0000000000..30919d27d6 --- /dev/null +++ b/definitions/npm/history_v5.x.x/flow_v0.201.x-/test_history_v5.x.x.js @@ -0,0 +1,343 @@ +// @flow +import { describe, it } from 'flow-typed-test'; + +import { + createBrowserHistory, + createMemoryHistory, + createHashHistory, + createPath, + parsePath, + locationsAreEqual, + createLocation, + type Action, + type Location, +} from 'history'; + +// browser history + +describe('browser history', () => { + it('should allow to get location fields', () => { + const history = createBrowserHistory({ + basename: '', + forceRefresh: false, + }); + + const pathname: string = history.location.pathname; + }); + + it('should allow to get browser and memory specific location fields', () => { + const history = createBrowserHistory({ + basename: '', + forceRefresh: false, + }); + + const key: string = history.location.key; + const state: { ... } = history.location.state; + }); + + it('should not allow to get field which is absent in the history', () => { + const history = createBrowserHistory({ + basename: '', + forceRefresh: false, + }); + + // $FlowExpectedError[prop-missing] + history.foo; + }); + + describe('#push', () => { + it('should allow to use string as first argument', () => { + const history = createBrowserHistory({ + basename: '', + forceRefresh: false, + }); + + history.push('/'); + }); + + it('should allow to use partial location as first argument', () => { + const history = createBrowserHistory({ + basename: '', + forceRefresh: false, + }); + + history.push({ + pathname: '/', + state: { a: 1 }, + }); + }); + }); + + describe('#replace', () => { + it('should allow to use string as first argument', () => { + const history = createBrowserHistory({ + basename: '', + forceRefresh: false, + }); + + history.replace('/'); + }); + + it('should allow to use partial location as first argument', () => { + const history = createBrowserHistory({ + basename: '', + forceRefresh: false, + }); + + history.replace({ + pathname: '/', + state: { a: 1 }, + }); + }); + }); +}); + +describe('memory history', () => { + it('should allow to get location fields', () => { + const history = createMemoryHistory({ + initialEntries: ['/'], + initialIndex: 0, + }); + + const pathname: string = history.location.pathname; + }); + + it('should allow to get browser and memory specific location fields', () => { + const history = createMemoryHistory({ + initialEntries: ['/'], + initialIndex: 0, + }); + + const key: string = history.location.key; + const state: { ... } = history.location.state; + }); + + it('should not allow to get field which is absent in the history', () => { + const history = createMemoryHistory({ + initialEntries: ['/'], + initialIndex: 0, + }); + + // $FlowExpectedError[prop-missing] + history.foo; + }); + + describe('#push', () => { + it('should allow to use string as first argument', () => { + const history = createMemoryHistory({ + initialEntries: ['/'], + initialIndex: 0, + }); + + history.push('/'); + }); + + it('should allow to use partial location as first argument', () => { + const history = createMemoryHistory({ + initialEntries: ['/'], + initialIndex: 0, + }); + + history.push({ + pathname: '/', + state: { a: 1 }, + }); + }); + }); + + describe('#replace', () => { + it('should allow to use string as first argument', () => { + const history = createMemoryHistory({ + initialEntries: ['/'], + initialIndex: 0, + }); + + history.replace('/'); + }); + + it('should allow to use partial location as first argument', () => { + const history = createMemoryHistory({ + initialEntries: ['/'], + initialIndex: 0, + }); + + history.replace({ + pathname: '/', + state: { a: 1 }, + }); + }); + }); +}); + +describe('hash history', () => { + it('should allow to get location fields', () => { + const history = createHashHistory({ + basename: '', + }); + + const pathname: string = history.location.pathname; + }); + + it('should not allow to get browser and memory specific location fields', () => { + const history = createHashHistory({ + basename: '', + }); + + // $FlowExpectedError[incompatible-type] + const key: string = history.location.key; + // $FlowExpectedError[incompatible-type] + const state: { ... } = history.location.state; + }); + + it('should not allow to get field which is absent in the history', () => { + const history = createHashHistory({ + basename: '', + }); + + // $FlowExpectedError[prop-missing] + history.foo; + }); + + describe('#push', () => { + it('should allow to use string as first argument', () => { + const history = createHashHistory({ + basename: '', + }); + + history.push('/'); + }); + + it('should allow to use partial location as first argument', () => { + const history = createHashHistory({ + basename: '', + }); + + history.push({ + search: '?a=1', + }); + }); + }); + + describe('#replace', () => { + it('should allow to use string as first argument', () => { + const history = createHashHistory({ + basename: '', + }); + + history.replace('/'); + }); + + it('should allow to use partial location as first argument', () => { + const history = createHashHistory({ + basename: '', + }); + + history.push({ + search: '?a=1', + }); + }); + }); +}); + +describe('create path', () => { + it('should allow to use Location argument', () => { + const path = createPath({ + pathname: '/test', + search: '?a=1', + hash: 'slug', + }); + + const key: string = path; + // $FlowExpectedError[incompatible-type] + const state: { ... } = path; + }); + + it('should not allow to accept void', () => { + // $FlowExpectedError[incompatible-call] + const path = createPath(); + + const key: string = path; + }); +}); + +describe('parse path', () => { + it('should allow to use string argument', () => { + const location = parsePath('/test?query#hash'); + + const state: { ... } = location; + // $FlowExpectedError[incompatible-type] + const key: string = location; + }); + + it('should not allow to accept void', () => { + // $FlowExpectedError[incompatible-call] + const location = parsePath(); + + const state: { ... } = location; + }); +}); + +describe('create location', () => { + it('should allow to use string argument', () => { + const location = createLocation('/test?query#hash'); + + const state: { ... } = location; + // $FlowExpectedError[incompatible-type] + const key: string = location; + }); + + it('should allow to use partial location as first argument', () => { + const location = createLocation({ + pathname: '/test', + search: '?a=1', + hash: 'slug', + }); + + const state: { ... } = location; + // $FlowExpectedError[incompatible-type] + const key: string = location; + }); +}); + +describe('locations are equal', () => { + it('should allow to use partial location as arguments and return boolean', () => { + const isEqual = locationsAreEqual( + { pathname: '/test' }, + { pathname: '/test', search: '?a=1' } + ); + + const bool: boolean = isEqual; + // $FlowExpectedError[incompatible-type] + const str: string = isEqual; + }); +}); + +describe('block api', () => { + const history = createBrowserHistory({ + basename: '', + }); + + it('returns a callable function', () => { + const unregister = history.block(() => {}); + unregister(); + + // $FlowExpectedError[extra-arg] accepts no args + unregister('test') + }); + + it('passes correct values into blocker', () => { + const unregister = history.block((({ action, location, retry }) => { + (action: Action); + (location: Location); + + retry(); + // $FlowExpectedError[extra-arg] accepts no args + retry('test'); + })); + }); + + it('blocker must be provided', () => { + // $FlowExpectedError[incompatible-call] + const unregister = history.block(); + }); +});