其他分享
首页 > 其他分享> > jest

jest

作者:互联网

beforeEach(() => {
   // 每次重新shallow组件,保证组件中的state是初始值, 并且比如有unmount,单测的书写顺序不受影响;
  c= shallow(<View />)
})
afterEach(() => {
       c.unmount();
    // 清空所以的mock,比如在一个测试用例中,某个mock函数执行了, jest.clearAllMocks(); 之后,mock函数会处于未执行状态
      jest.clearAllMocks();
  });

标签:unmount,shallow,clearAllMocks,jest,组件,mock
来源: https://www.cnblogs.com/Running00/p/15405707.html