---
title: "写Unit Test的坑"
author: "lyj86"
date: "2020-02-06T22:29:37Z"
tags: []
categories: ["Web前端"]
slug: "unit-test"
draft: false
lastmod: "2020-02-06T22:29:37Z"
id: 2512270
url: "https://lyj86.iteye.com/blog/2512270"
---

写Angular的UT，经常要spyOn某些service的方法，防止发送网络请求。在spec文件和普通文件中引入类的方式不同，就会导致spyOn不起作用，代码依然调用没有mock掉的方法，比如

spec中使用 '../../../libs/xxxx' 这种相对路径引入文件

普通文件中使用 ’libs/xxxx' 这种方式引入文件