第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

在 Enzyme 描述函數(shù)中安裝和卸載的位置?

在 Enzyme 描述函數(shù)中安裝和卸載的位置?

寶慕林4294392 2021-06-09 17:49:10
我正在嘗試在 React 項(xiàng)目中掌握測試組件的竅門。到目前為止,我在單個(gè)組件上有一個(gè)測試文件,我正在嘗試將此文件準(zhǔn)備為包含多個(gè)測試的測試套件。import React from 'react';import Enzyme, { mount } from 'enzyme';import Adapter from 'enzyme-adapter-react-16';import HamburgerIcon from './HamburgerIcon';Enzyme.configure({ adapter: new Adapter() });describe('<HamburgerIcon />', () => {  const hamburgerIcon = mount(<HamburgerIcon showOverlay={showOverlay} />);  it('displays on mobile', () => {     ...     ...  });  it('has class .open after click', () => {    ...    ...  });  hamburgerIcon.unmount();});我已經(jīng)刪除了兩個(gè)測試的內(nèi)容,但基本上這兩個(gè)測試都包含在一個(gè)describe函數(shù)中,并且我正在嘗試mount使用一次組件和unmount一次組件以保持干燥(不要重復(fù)自己) .我mount將兩個(gè)it函數(shù)放在之前,認(rèn)為在運(yùn)行測試之前安裝組件是合乎邏輯的。我unmount在兩個(gè)測試函數(shù)之后放置了,這導(dǎo)致了錯(cuò)誤:方法“模擬”旨在在 1 個(gè)節(jié)點(diǎn)上運(yùn)行。0 找到了。我認(rèn)為這是因?yàn)樵趯?shí)際運(yùn)行測試之前組件正在卸載。如果我mount和unmount在這兩個(gè)測試中,像這樣......describe('<HamburgerIcon />', () => {  it('displays on mobile', () => {     const hamburgerIcon = mount(<HamburgerIcon showOverlay={showOverlay} />);     ...     ...     hamburgerIcon.unmount();  });  it('has class .open after click', () => {    const hamburgerIcon = mount(<HamburgerIcon showOverlay={showOverlay} />);    ...    ...    hamburgerIcon.unmount();  });});...測試通過。不過,這似乎有些過分。如果我的測試套件有十個(gè)測試功能呢?我應(yīng)該在每次測試時(shí)都像這樣安裝和卸載嗎?
查看完整描述

1 回答

?
婷婷同學(xué)_

TA貢獻(xiàn)1844條經(jīng)驗(yàn) 獲得超8個(gè)贊

您可以使用 beforeEach 和 afterEach 函數(shù)來設(shè)置和清除您的測試。


afterEach(() => {

    //do the unmounting and other stuff here

    //this will be called after each test case

});


beforeEach(() => {

    //do the mounting and setting up the test case here

    //this will be called before each test case

});


查看完整回答
反對 回復(fù) 2021-06-18
  • 1 回答
  • 0 關(guān)注
  • 110 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)