NgTest使用总结(个人简洁版

96 阅读1分钟

技术使用

  • Karma+Jasmine juejin.cn/post/684490… 或者在Angular官方资源中可查看具体方法
  • StoryBook 测试组件 很少用,感觉没用过 黑盒测试

区别

  1. 均可测pipe,service,componment
  2. 官方测试框架可测 Router componment的界面元素, input , output
  3. storybook能测的 componment交互测试,组件管理,编写组件文档

用法

  1. describe 定义整体测试描述方法
  2. it 定义断言方法(描述)
  3. expect断言(juejin.cn/post/701576…)
  • 具体方法:
  • toBe
  • toEqual
  • toMatch
  • toBeDefined
  • toBeNull
  • toBeTruthy
  • toBeFalsy
  • toContain
  • toBeLessThan
  • toBeGreaterThan
  • toBeCloseTo
  • toThrow
  • toHaveBeenCalled
  • toHaveBeenCalledWith