Skip to content

Commit 152c3c7

Browse files
authored
fix(options): allow omitting options (#135)
* setup jest * add first test case * Run tests on the ci * fix rootDir behavior * updated test case to detect missing promises * fix failing test
1 parent 16ad92c commit 152c3c7

File tree

7 files changed

+1558
-35
lines changed

7 files changed

+1558
-35
lines changed

.circleci/config.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ jobs:
4141
- run: npx bundlesize
4242
- save-cache: *save-cache
4343

44+
Test:
45+
docker:
46+
- image: circleci/node:8
47+
steps:
48+
- checkout
49+
- restore-cache: *restore-cache
50+
- *install
51+
- run:
52+
command: yarn test --ci --runInBand
53+
- store_test_results:
54+
path: reports
55+
4456
Semantic Release:
4557
docker:
4658
- image: circleci/node:8
@@ -57,10 +69,12 @@ workflows:
5769
jobs:
5870
- Typecheck
5971
- Build
72+
- Test
6073
- Semantic Release:
6174
requires:
6275
- Typecheck
6376
- Build
77+
- Test
6478
filters:
6579
branches:
6680
only:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ dist
6161
es
6262
typings
6363
umd
64+
reports
6465
/*.js
6566
!.babelrc.js
6667
!rollup.config.js

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"precommit": "lint-staged",
2929
"dev": "concurrently 'tsc --noEmit --watch' 'yarn build:cjs --watch' 'yarn build:es --watch' 'yarn build:umd --watch' 'yarn build:umd.min --watch'",
3030
"prepublishOnly": "unset npm_config_cafile && yarn build",
31+
"test": "jest",
3132
"typecheck": "tsc --noEmit"
3233
},
3334
"dependencies": {
@@ -39,6 +40,7 @@
3940
"@babel/plugin-external-helpers": "7.0.0-beta.54",
4041
"@babel/preset-env": "7.0.0-beta.54",
4142
"@babel/preset-typescript": "7.0.0-beta.54",
43+
"@types/jest": "23.3.0",
4244
"babel-eslint": "8.2.6",
4345
"babel-plugin-add-module-exports": "0.2.1",
4446
"babel-plugin-dev-expression": "0.2.1",
@@ -48,6 +50,8 @@
4850
"eslint-plugin-import": "2.13.0",
4951
"eslint-plugin-react": "7.10.0",
5052
"husky": "0.14.3",
53+
"jest": "23.4.1",
54+
"jest-junit": "5.1.0",
5155
"lint-staged": "7.2.0",
5256
"prettier": "1.13.7",
5357
"prettier-package-json": "1.6.0",
@@ -59,6 +63,7 @@
5963
"rollup-plugin-replace": "2.0.0",
6064
"rollup-plugin-terser": "1.0.1",
6165
"semantic-release": "15.8.0",
66+
"ts-jest": "23.0.1",
6267
"typescript": "2.9.2"
6368
},
6469
"keywords": [
@@ -87,6 +92,29 @@
8792
"compression": "none"
8893
}
8994
],
95+
"jest": {
96+
"transform": {
97+
"^.+\\.ts$": "ts-jest"
98+
},
99+
"testRegex": "(/tests/.*|(\\.|/)(test|spec))\\.(js|ts)$",
100+
"moduleFileExtensions": [
101+
"ts",
102+
"tsx",
103+
"js",
104+
"jsx",
105+
"json",
106+
"node"
107+
],
108+
"reporters": [
109+
"default",
110+
[
111+
"jest-junit",
112+
{
113+
"output": "reports/jest/results.xml"
114+
}
115+
]
116+
]
117+
},
90118
"lint-staged": {
91119
"*.js": [
92120
"prettier --write",

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ function scroll(target: Element, options?: SmoothBehaviorOptions): Promise<any>
102102
function scroll<T>(target: Element, options: CustomBehaviorOptions<T>): T
103103
function scroll(target: Element, options: StandardBehaviorOptions): void
104104
function scroll<T>(target: Element, options?: any) {
105-
if (shouldSmoothScroll<SmoothBehaviorOptions>(options)) {
106-
const overrides = options || {}
105+
const overrides = options || {}
106+
if (shouldSmoothScroll<SmoothBehaviorOptions>(overrides)) {
107107
// @TODO replace <any> in promise signatures with better information
108108
return scrollIntoView<Promise<any>>(target, {
109109
block: overrides.block,

tests/interface.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import scrollIntoView from '../src'
2+
3+
jest.mock(
4+
'scroll-into-view-if-needed',
5+
() => (_target: Element, options: any) => options.behavior([])
6+
)
7+
8+
test('options is optional', () => {
9+
expect.assertions(1)
10+
return expect(scrollIntoView(document.body)).resolves.toEqual([])
11+
})

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"target": "es5",
44
"module": "es2015",
55
"moduleResolution": "node",
6+
"esModuleInterop": true,
67
"declaration": true,
78
"rootDir": "src",
89
"declarationDir": "typings",
@@ -17,5 +18,5 @@
1718
"alwaysStrict": true,
1819
"lib": ["es5", "es2015.promise", "dom"]
1920
},
20-
"exclude": ["dist", "example", "**/*-test.ts", "cypress"]
21+
"exclude": ["tests"]
2122
}

0 commit comments

Comments
 (0)