Skip to content

Commit

Permalink
feat: update web test (#250)
Browse files Browse the repository at this point in the history
Co-authored-by: yitan.lgh <yitan.lgh@alibaba-inc.com>
  • Loading branch information
汉堡鸡肉卷鸡腿鸡翅 and yitan.lgh committed Nov 8, 2021
1 parent b07720b commit 291ef2a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/packages/navigate/__test__/web.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,25 @@ testWebAPI('navigate', async (globals) => {
pushState: mockPushState,
replaceState: mockReplaceState,
};
Object.defineProperty(window, 'history', {
value: globals.history,
});
globals.location = Object.defineProperty({}, 'href', {
set: mockSetLocation,
});

const { push, back, reLaunch, switchTab, replace, go } = require('../src/index');

await push({ url: '/a' });
expect(mockSetLocation.mock.calls).toEqual([['/a']]);
const state = { page_id: 1 };
const title = '';
expect(mockPushState.mock.calls).toEqual([[state, title, '/a']]);

await back();
expect(mockGo.mock.calls).toEqual([[-1]]);

await replace({ url: '/d' });
expect(mockReplaceState.mock.calls).toEqual([['', '', '/d']]);
await replace({ url: '/a.html' });
expect(mockReplaceState.mock.calls).toEqual([[null, null, '/a.html']]);

mockGo.mockClear();
await go({ step: -2 });
Expand Down
2 changes: 1 addition & 1 deletion src/packages/navigate/src/web/replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CONTAINER_NAME } from '@utils/constant';

export const replace = normalize.replace((options?: IReplaceOptions) => {
const { url, isHash = false, success, fail, complete } = options || {};
const _url = isHash ? `/#${ url}` : url;
const _url = isHash ? `/#${url}` : url;
setTimeout((): void => {
try {
if (isHash) {
Expand Down

0 comments on commit 291ef2a

Please sign in to comment.