Skip to content

Commit d8d4b0f

Browse files
authored
test: Add some simple TS tests to catch regressions (#112)
1 parent 64b973c commit d8d4b0f

File tree

5 files changed

+49
-10
lines changed

5 files changed

+49
-10
lines changed

package-lock.json

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"prepare": "npx simple-git-hooks",
1212
"build": "microbundle -f cjs,es,umd --no-generateTypes",
1313
"lint": "eslint src/*.{js,jsx}",
14-
"test": "wtr src/*.test.{js,jsx}",
14+
"test": "npm run test:types & npm run test:browser",
15+
"test:browser": "wtr test/*.test.{js,jsx}",
16+
"test:types": "tsc -p test/",
1517
"prettier": "prettier **/*.{js,jsx} --write",
1618
"prepublishOnly": "npm run build && npm run lint && npm run test"
1719
},
@@ -22,6 +24,7 @@
2224
"version": "16.8"
2325
}
2426
},
27+
"ignorePatterns": ["*.ts", "*.tsx"],
2528
"rules": {
2629
"brace-style": "off",
2730
"jest/expect-expect": "off",
@@ -75,7 +78,8 @@
7578
"nano-staged": "^0.8.0",
7679
"preact": "^10.27.1",
7780
"prettier": "^2.1.1",
78-
"simple-git-hooks": "^2.13.1"
81+
"simple-git-hooks": "^2.13.1",
82+
"typescript": "^5.9.2"
7983
},
8084
"simple-git-hooks": {
8185
"pre-commit": "npx nano-staged"

src/index.test.jsx renamed to test/index.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { assert } from '@open-wc/testing';
22
import { h, createContext, Component, Fragment } from 'preact';
33
import { useContext } from 'preact/hooks';
44
import { act } from 'preact/test-utils';
5-
import registerElement from './index';
5+
import registerElement from '../src/index';
66

77
/** @param {string} name */
88
function createTestElement(name) {

test/tsconfig.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"module": "NodeNext",
5+
"moduleResolution": "NodeNext",
6+
"noEmit": true,
7+
"skipLibCheck": true,
8+
"jsx": "react",
9+
"jsxFactory": "h",
10+
"jsxFragmentFactory": "Fragment",
11+
},
12+
"include": ["./types.test.tsx"],
13+
}

test/types.test.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { h } from 'preact';
2+
import registerElement from '../src/index';
3+
4+
interface AppProps {
5+
name: string;
6+
}
7+
8+
function App(props: AppProps) {
9+
return <h1>Hello {props.name}!</h1>;
10+
}
11+
12+
registerElement(App, 'my-app', ['name']);
13+
14+
// @ts-expect-error `bar` is not a valid prop, so it should not be an observed attribute
15+
registerElement(App, 'my-app', ['name', 'bar']);
16+
17+
registerElement(App, 'my-app-shadow', ['name'], {
18+
shadow: false,
19+
// @ts-expect-error should not set shadow DOM mode when `shadow` is false
20+
mode: 'open',
21+
});

0 commit comments

Comments
 (0)