Skip to content

Commit 8e21b06

Browse files
committed
feat(typescript): finish code to typescript
1 parent d4a58f1 commit 8e21b06

File tree

5 files changed

+48
-39
lines changed

5 files changed

+48
-39
lines changed

package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,6 @@
105105
"tsx",
106106
"js"
107107
],
108-
"globals": {
109-
"ts-jest": {
110-
"tsConfigFile": "tsconfig.json"
111-
}
112-
},
113108
"setupTestFrameworkScriptFile": "<rootDir>/test/setup.ts",
114109
"coveragePathIgnorePatterns": [
115110
"<rootDir>/test/",

src/__test__/index.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as All from '..'
2+
import Image from '../lib/Image'
3+
import ImgPreview, { PreviewApi } from '../lib/ImgPreview'
4+
describe('test export lib', () => {
5+
it('export Image', () => {
6+
expect(All.Image).toBe(Image)
7+
})
8+
it('export ImgPreview', () => {
9+
expect(All.Preview).toBe(ImgPreview)
10+
})
11+
it('export PreviewApi', () => {
12+
expect(All.PreviewApi).toBe(PreviewApi)
13+
})
14+
})

src/lib/Image/__test__/Image.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('test img when IntersectionObserver is false', () => {
4848
it('test group & preview prop', () => {
4949
const group = '100'
5050
const result = shallow<ImageComponent>(getComp({ group: group }))
51-
expect(result.find('.mask-img').getDOMNode().getAttribute('data-img-group')).toEqual('100')
51+
expect(result.find('.mask-img').prop('data-img-group')).toEqual('100')
5252
})
5353
it('data-index-group is "null" when preview is false', () => {
5454
const result = shallow<ImageComponent>(getComp({ group: '100', preview: false }))

src/lib/Image/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default class ReactImage extends PureComponent<iImageProp> {
8787
width: 100,
8888
group: 'default',
8989
objectFit: 'cover',
90-
previe: true,
90+
preview: true,
9191
mask: true
9292
}
9393
refDom: RefObject<HTMLDivElement> = null

src/lib/ImgPreview/__test__/ImgPreview.test.tsx

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -380,35 +380,35 @@ describe('test getInstance', () => {
380380
})
381381
})
382382

383-
// describe('test api', () => {
384-
// it('test api', () => {
385-
// const preview = jest.fn()
386-
// const show = jest.fn()
387-
// const hide = jest.fn()
388-
// const destroy = jest.fn()
389-
// ImgPreview.newInstance = function(callback) {
390-
// callback({
391-
// preview(current, list) {
392-
// preview(current, list)
393-
// },
394-
// show() {
395-
// show()
396-
// },
397-
// component: {} as ImgPreview,
398-
// hide() {
399-
// hide()
400-
// },
401-
// destroy
402-
// })
403-
// }
404-
// PreviewApi.preview('1', ['1', '2'])
405-
// expect(preview).toBeCalledTimes(1)
406-
// expect(preview).toBeCalledWith('1', ['1', '2'])
407-
// PreviewApi.show()
408-
// expect(show).toBeCalledTimes(1)
409-
// PreviewApi.hide()
410-
// expect(hide).toBeCalledTimes(1)
411-
// PreviewApi.destroy()
412-
// expect(destroy).toBeCalledTimes(1)
413-
// })
414-
// })
383+
describe('test api', () => {
384+
it('test api', () => {
385+
const preview = jest.fn()
386+
const show = jest.fn()
387+
const hide = jest.fn()
388+
const destroy = jest.fn()
389+
ImgPreview.newInstance = function(callback) {
390+
callback({
391+
preview(current, list) {
392+
preview(current, list)
393+
},
394+
show() {
395+
show()
396+
},
397+
component: {} as ImgPreview,
398+
hide() {
399+
hide()
400+
},
401+
destroy
402+
})
403+
}
404+
PreviewApi.preview('1', ['1', '2'])
405+
expect(preview).toBeCalledTimes(1)
406+
expect(preview).toBeCalledWith('1', ['1', '2'])
407+
PreviewApi.show()
408+
expect(show).toBeCalledTimes(1)
409+
PreviewApi.hide()
410+
expect(hide).toBeCalledTimes(1)
411+
PreviewApi.destroy()
412+
expect(destroy).toBeCalledTimes(1)
413+
})
414+
})

0 commit comments

Comments
 (0)