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

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

如何使用 Jest 測(cè)試 React 組件

如何使用 Jest 測(cè)試 React 組件

慕尼黑8549860 2019-03-03 14:00:56
如何使用 Jest 測(cè)試 React 組件
查看完整描述

1 回答

?
慕容708150

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

// React源碼

// Link.react.js

import React from 'react';

 

const STATUS = {

  NORMAL: 'normal',

  HOVERED: 'hovered',

};

 

export default class Link extends React.Component {

 

  constructor() {

    super();

 

    this._onMouseEnter = this._onMouseEnter.bind(this);

    this._onMouseLeave = this._onMouseLeave.bind(this);

 

    this.state = {

      class: STATUS.NORMAL,

    };

  }

 

  _onMouseEnter() {

    this.setState({class: STATUS.HOVERED});

  }

 

  _onMouseLeave() {

    this.setState({class: STATUS.NORMAL});

  }

 

  render() {

    return (

      <a

        className={this.state.class}

        href={this.props.page || '#'}

        onMouseEnter={this._onMouseEnter}

        onMouseLeave={this._onMouseLeave}>

        {this.props.children}

      </a>

    );

  }

 

}

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

// 測(cè)試代碼

// Link.react-test.js

import React from 'react';

import Link from '../Link.react';

import renderer from 'react-test-renderer';

 

test('Link changes the class when hovered', () => {

  const component = renderer.create(

    <Link page="

  );

  let tree = component.toJSON();

  expect(tree).toMatchSnapshot();

 

  // manually trigger the callback

  tree.props.onMouseEnter();

  // re-rendering

  tree = component.toJSON();

  expect(tree).toMatchSnapshot();

 

  // manually trigger the callback

  tree.props.onMouseLeave();

  // re-rendering

  tree = component.toJSON();

  expect(tree).toMatchSnapshot();

});


 


查看完整回答
反對(duì) 回復(fù) 2019-03-10
  • 1 回答
  • 0 關(guān)注
  • 1176 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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