Skip to content

Commit

Permalink
Merge pull request #20 from tidbcloud/feat/unit-test
Browse files Browse the repository at this point in the history
Feat/unit test
  • Loading branch information
zhangc110033 authored Jun 25, 2024
2 parents 748c9a9 + 2bcc0b1 commit be812a9
Show file tree
Hide file tree
Showing 6 changed files with 6,052 additions and 3,815 deletions.
7 changes: 7 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
presets: [
'@babel/preset-env',
'@babel/preset-react',
'@babel/preset-typescript'
]
}
8 changes: 8 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
testEnvironment: 'jsdom',
transform: {
'^.+\\.(ts|tsx)?$': 'babel-jest',
'^.+\\.(js|jsx)$': 'babel-jest'
}
}
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"prepare": "husky",
"dev": "pnpm -r --parallel dev",
"build": "pnpm -r build",
"test": "jest",
"release": "changeset publish"
},
"keywords": [
Expand All @@ -18,10 +19,22 @@
"author": "",
"license": "MIT",
"devDependencies": {
"@babel/preset-env": "^7.24.7",
"@babel/preset-react": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@changesets/cli": "^2.27.5",
"@testing-library/dom": "^10.1.0",
"@testing-library/jest-dom": "^6.4.6",
"@testing-library/react": "^16.0.0",
"@types/jest": "^29.5.12",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"babel-jest": "^29.7.0",
"concurrently": "^8.2.2",
"eslint": "^9.4.0",
"husky": "^9.0.11",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"lint-staged": "^15.2.5",
"prettier": "^3.3.1"
},
Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/test/instance.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createSQLEditorInstance } from '../editor-instance'

function sum(a: number, b: number) {
return a + b
}

test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3)
})

test('create instance successfully', () => {
const instance = createSQLEditorInstance({
editorId: '111',
doc: '222'
})
expect(instance.editorId).toBe('111')
})
14 changes: 14 additions & 0 deletions packages/react/src/test/react-component.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { render, screen } from '@testing-library/react'
// import SQLEditor from '../sql-editor'
import '@testing-library/jest-dom'
// @ts-ignore
import React from 'react'

const Example = () => {
return <input></input>
}

test('test with react-testing-library', () => {
render(<Example />)
expect(screen.getByRole('textbox')).toBeEnabled()
})
Loading

0 comments on commit be812a9

Please sign in to comment.