Skip to content
This repository was archived by the owner on Jan 27, 2023. It is now read-only.

Commit 30ba5a7

Browse files
committed
mode function to utils file and add test
1 parent 5c2544b commit 30ba5a7

11 files changed

+2392
-134
lines changed

.babelrc

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
}
1313
]
1414
],
15-
"plugins": ["transform-class-properties", "external-helpers"],
15+
"plugins": ["transform-class-properties"],
1616
"env": {
1717
"test": {
1818
"plugins": ["transform-es2015-modules-commonjs"]
1919
},
20-
"development": {},
20+
"development": {
21+
"plugins": ["external-helpers"]
22+
},
2123
"production": {}
2224
}
2325
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`get scroll 10 value 1`] = `10`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`3 url insert 1`] = `
4+
Array [
5+
Object {
6+
"pathname": "/bar",
7+
"scroll": 0,
8+
},
9+
Object {
10+
"pathname": "/foo",
11+
"scroll": 0,
12+
},
13+
]
14+
`;
15+
16+
exports[`no array in first param 1`] = `
17+
Array [
18+
Object {
19+
"pathname": "/",
20+
"scroll": 0,
21+
},
22+
]
23+
`;
24+
25+
exports[`only 2 params 1`] = `
26+
Array [
27+
Object {
28+
"pathname": "/",
29+
"scroll": 0,
30+
},
31+
]
32+
`;

__tests__/getScrollPage.spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { getScrollPage } from '../src/utils/utils';
2+
3+
test('get scroll 10 value', () => {
4+
Object.defineProperty(window, 'pageYOffset', { value: 10, writable: true });
5+
const r = getScrollPage();
6+
expect(r).toMatchSnapshot();
7+
});

__tests__/saveUrl.spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { saveUrl } from '../src/utils/utils';
2+
3+
test('no array in first param', () => {
4+
const r = saveUrl('lol', '/', 0);
5+
expect(r).toMatchSnapshot();
6+
});
7+
8+
test('only 2 params', () => {
9+
const r = saveUrl('lol', '/');
10+
expect(r).toMatchSnapshot();
11+
});
12+
13+
test('3 url insert', () => {
14+
let url = [];
15+
url = saveUrl(url, '/');
16+
url = saveUrl(url, '/foo');
17+
url = saveUrl(url, '/bar');
18+
expect(url).toMatchSnapshot();
19+
});

__tests__/scrollTo.spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { scrollTo } from '../src/utils/utils';
2+
3+
test('scrollTo 100', () => {
4+
global.scrollTo = jest.fn();
5+
global.requestAnimationFrame = jest.fn(cb => {
6+
cb();
7+
});
8+
scrollTo(100);
9+
expect(global.scrollTo).toHaveBeenCalledWith(0, 100);
10+
});

dist/ScrollMemory.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)