Skip to content

Commit

Permalink
feat: add typescript (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlaessig authored Feb 19, 2023
1 parent 75edae4 commit 22f9a5a
Show file tree
Hide file tree
Showing 10 changed files with 3,130 additions and 3,795 deletions.
24 changes: 8 additions & 16 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
{
"extends": ["airbnb", "plugin:prettier/recommended"],

"parser": "babel-eslint",
"extends": ["airbnb", "plugin:prettier/recommended", "eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "jest", "react", "prettier"],
"root": true,

"parserOptions": {
"ecmaFeatures": {
"jsx": true
}
},

"globals": {
"fetch": false
},

"env": {
"es6": true,
"jest/globals": true
},

"plugins": ["jest", "react", "prettier"],

"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".ios.js", ".android.js"]
"extensions": [".js", ".tsx"]
}
}
},

"ignorePatterns": ["dist"],

"rules": {
"prettier/prettier": "error",
"camelcase": "off",
Expand All @@ -44,7 +36,7 @@
"react/destructuring-assignment": "off",
"react/forbid-prop-types": "off",
"react/jsx-boolean-value": ["error", "always"],
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx", ".tsx"] }],
"react/jsx-uses-react": "error",
"react/jsx-uses-vars": "error",
"react/require-default-props": "off",
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: '18.x'
- name: Install
run: yarn
- name: Build
run: yarn build
- name: Release
run: npx semantic-release
env:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ jobs:
run: yarn install
- name: Test
run: yarn test
- name: Build
run: yarn build
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Xcode
#
build/
dist/
*.pbxuser
!default.pbxuser
*.mode1v3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import renderer from 'react-test-renderer';
import { FlatList, Text, TextInput, View } from 'react-native';
import Autocomplete from '..';
import Autocomplete from '../index';

const ITEMS = [
'A New Hope',
Expand All @@ -10,11 +10,9 @@ const ITEMS = [
'The Phantom Menace',
'Attack of the Clones',
'Revenge of the Sith',
];
] as const;

describe('<AutocompleteInput />', () => {
FlatList.propTypes = {};

it('should hide suggestion list on initial render', () => {
const r = renderer.create(<Autocomplete data={[]} />);
const autocomplete = r.root;
Expand Down Expand Up @@ -61,7 +59,7 @@ describe('<AutocompleteInput />', () => {
const autocomplete = testRenderer.root;
const customTextInput = autocomplete.findByType(Text);

expect(customTextInput.children[0].children).toEqual([text]);
expect((customTextInput.children[0] as { children: unknown[] }).children).toEqual([text]);
expect(autocomplete.findAllByType(TextInput)).toHaveLength(0);
});

Expand Down Expand Up @@ -103,7 +101,7 @@ describe('<AutocompleteInput />', () => {
data={ITEMS}
renderResultList={({ data, style }) => (
<View style={style}>
{data.map((item, index) => (
{data?.map((item, index) => (
// eslint-disable-next-line react/no-array-index-key
<Text key={index}>{item}</Text>
))}
Expand All @@ -113,7 +111,6 @@ describe('<AutocompleteInput />', () => {
);

const autocomplete = testRenderer.root;

expect(autocomplete.findAllByType(FlatList)).toHaveLength(0);

const texts = autocomplete.findAllByType(Text);
Expand All @@ -124,6 +121,7 @@ describe('<AutocompleteInput />', () => {
const inputRef = React.createRef();

renderer.create(<Autocomplete data={ITEMS} ref={inputRef} />);
expect(inputRef.current._reactInternals.elementType.displayName).toBe('TextInput');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((inputRef.current as any)._reactInternals.elementType.displayName).toBe('TextInput');
});
});
Loading

0 comments on commit 22f9a5a

Please sign in to comment.