Javascript Unit Testing - DOM Manipulation

后端 未结 3 1182
半阙折子戏
半阙折子戏 2021-02-18 19:09

I\'m quite new to Javacript Unit testing. One thing keep bothering me. When testing javascript, we often need to do the DOM manipulation. It looks like I am unit testing a metho

3条回答
  •  耶瑟儿~
    2021-02-18 19:59

    One of the toughest parts of javascript unit testing is not the testing, it's learning how to architect your code so that it is testable.

    You need to structure your code with a clear separation of testable logic and DOM manipulation.

    My rule of thumb is this:

    If you are testing anything that is dependent on the DOM structure, then you are doing it wrong.

    In summary:Try to test data manipulations and logical operations only.

提交回复
热议问题