Jest: ๋‹ค์Œ์„ ํฌํ•จํ•˜๋Š” ๊ตฌ์„ฑ ์š”์†Œ์— ๋Œ€ํ•ด "TypeError: ์ •์˜๋˜์ง€ ์•Š์€ '_tag' ์†์„ฑ์„ ์ฝ์„ ์ˆ˜ ์—†์Œ"๊ณผ ํ•จ๊ป˜ React Native ์Šค๋ƒ…์ƒท์ด ์‹คํŒจํ•ฉ๋‹ˆ๋‹ค.<textinput/>

์— ๋งŒ๋“  2016๋…„ 08์›” 06์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: facebook/jest

์žฌํ˜„ํ•˜๋ ค๋ฉด:

  1. https://github.com/facebook/jest/blob/master/examples/react-native/Intro.js ๋ฅผ ์ˆ˜์ •ํ•˜์—ฌ render()์— <TextInput />์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
  2. npm ํ…Œ์ŠคํŠธ

๊ฒฐ๊ณผ:

FAIL ํ…Œ์ŠคํŠธ /Intro-test.js(0.459์ดˆ)
โ— ์†Œ๊ฐœ โ€บ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ๋ Œ๋”๋ง๋ฉ๋‹ˆ๋‹ค.

  • TypeError: ์ •์˜๋˜์ง€ ์•Š์€ '_tag' ์†์„ฑ์„ ์ฝ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.
    ReactNativeBaseComponent.Mixin.mountComponent์—์„œ (node_modules/react/lib/ReactNativeBaseComponent.js:179:45)
    Object.ReactReconciler.mountComponent์—์„œ (node_modules/react/lib/ReactReconciler.js:47:35)
    ReactCompositeComponentMixin.performInitialMount์—์„œ (node_modules/react/lib/ReactCompositeComponent.js:397:34)
    ReactCompositeComponentMixin.mountComponent์—์„œ (node_modules/react/lib/ReactCompositeComponent.js:262:21)
    Object.ReactReconciler.mountComponent์—์„œ (node_modules/react/lib/ReactReconciler.js:47:35)
    ReactCompositeComponentMixin.performInitialMount์—์„œ (node_modules/react/lib/ReactCompositeComponent.js:397:34)
    ReactCompositeComponentMixin.mountComponent (node_modules/react/lib/ReactCompositeComponent.js:262:21)
    Object.ReactReconciler.mountComponent์—์„œ (node_modules/react/lib/ReactReconciler.js:47:35)
    ReactMultiChild.Mixin.mountChildren์—์„œ (node_modules/react/lib/ReactMultiChild.js:242:44)
    ReactTestComponent.mountComponent (node_modules/react/lib/ReactTestRenderer.js:53:8)

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

https://facebook.github.io/jest/docs/tutorial-react-native.html#mock -native-modules-using-jest-mock์— ๋”ฐ๋ผ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ์„ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

jest.mock('TextInput', () => 'TextInput');

ํ…Œ์ŠคํŠธ ์‹œ์ž‘๊นŒ์ง€.

๋ชจ๋“  3 ๋Œ“๊ธ€

https://facebook.github.io/jest/docs/tutorial-react-native.html#mock -native-modules-using-jest-mock์— ๋”ฐ๋ผ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ์„ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

jest.mock('TextInput', () => 'TextInput');

ํ…Œ์ŠคํŠธ ์‹œ์ž‘๊นŒ์ง€.

TextInput์— ๋Œ€ํ•œ ๊ธฐ๋ณธ ๋ชจ์˜๋ฅผ ์ œ๊ณตํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Jest 15์˜ ๊ฒฝ์šฐ https://github.com/facebook/jest/pull/1516 ์—์„œ ์ˆ˜์ •๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰