vue 单元测试报错之 undefined is not a constructor (evaluating 'expect(vmComponent.count).toBe(1)')
下面是按照vue官方的例子,写的测试,
// MyComponent.spec.js import Vue from 'vue'
import MyComponent from '@/components/MyComponent.vue'describe('MyComponent', () => {// 检查原始组件选项it('has a created hook', () => {expect(typeof MyComponent.created).toBe('function')})// 评估原始组件选项中的函数的结果it('sets the correct default data', () => {expect(typeof MyComponent.data).toBe('function')const defaultData = MyComponent.data()expect(defaultData.message).toBe('hello!')})
})
运行npm run unit一直提示:undefined is not a constructor (evaluating 'expect(vmComponent.count).toBe(function)')
网上百度了不少答案,下面总结了下:
自带的phantomJs浏览器的时候会报错,所以需要安装karma-chrome-launcher
npm i -D karma-chrome-launcher
可以查看官方文档,有说明:
安装完后再在karma.conf.js中将 browsers: ['PhantomJS']改成browsers: ['Chrome']
再次运行npm run unit之前的错误没有了,但是会出现新的错误:Error: Invalid Chai property: toBe. Did you mean "to"?
无效的Chai属性:toBe
去查看了下当前项目的package.json发现我们使用的是chai断言库,而vue官方使用的是Jasmine断言库
找到问题就好办了,我们去查看下chai的文档 ,将之前的代码的toBe()换成to.equal(),然后再次运行代码,就ok了。
觉得博主写的不错的,请给博主一个赞吧!
vue 单元测试报错之 undefined is not a constructor (evaluating 'expect(vmComponent.count).toBe(1)')相关推荐
- gcc编译报错:undefined reference to `std::cout‘
1 问题描述 下面的一段代码(代码来源)在使用gcc编译的时候报错:undefined reference tostd::cout'` 编译文件:test.cpp内容如下: #include < ...
- java test报错_Java 单元测试报错
«Java 单元测试报错:Test class should have exactly one public zero-argument constructor» public class Test{ ...
- Vue项目 报错TypeError [ERR INVALID ARG TYPE]: The “path“ argument must be of type string
# Vue项目 报错TypeError [ERR INVALID ARG TYPE]: The "path" argument must be of type string 卡了半 ...
- vue index.php,如何解决vue $index报错问题
vue $index报错是因为vue已经移除了原来的$index和$key用法,变成了index和key,其解决办法就是修改$index和$key为index和key即可. 本教程操作环境:windo ...
- Vue项目报错:This relative module was not found
Vue项目报错:This relative module was not found 问题如下 解决办法 出现这种错误检查自己的路径问题 我已解决 "./ ":代表当前所在的目录. ...
- 解决Vue项目报错:Expected indentation of 2 spaces but found 4. eslint(indent) [8, 1]的方法
解决Vue项目报错:Expected indentation of 2 spaces but found 4. eslint(indent) [8, 1]的方法 报错如下 问题分析 明显从图中可以以看 ...
- Vue工程报错解决方案Warn:import Vue from “vue“;
Vue工程报错解决方案Warn:import Vue from "vue"; 参考文章: (1)Vue工程报错解决方案Warn:import Vue from "vue& ...
- 记一次升级node版本后,运行原vue项目报错问题解决方法
记一次升级node版本后,运行原vue项目报错问题解决方法 参考文章: (1)记一次升级node版本后,运行原vue项目报错问题解决方法 (2)https://www.cnblogs.com/happ ...
- eslint 验证vue文件 报错 unexpected token =解决方法
eslint 验证vue文件 报错 unexpected token =解决方法 参考文章: (1)eslint 验证vue文件 报错 unexpected token =解决方法 (2)https: ...
最新文章
- 一阶微分算子锐化图像_【动手学计算机视觉】第三讲:图像预处理之图像分割...
- 大学期间可以获得哪些荣誉_大学期间没有什么荣誉经历,该怎么写简历呢?找工作会很难吗?...
- degree of freedom of a leg of a dog
- 实验吧逆向catalyst-system——WP
- java 合并到一行_mysql中将多行数据合并成一行数据
- 用OC和Swift一起说说二叉树
- 计算机网络(十八)-以太网
- java 获取对象方法有哪些方法有哪些方法有哪些_Java中创建String 对象的方法有哪些...
- 【window】git安装教程
- linux管理员清理主目录,在Linux上如何清理垃圾系统管理员
- RabbitMQ Tutorials 3 - Publish/Subscribe 发布/订阅
- c++解释--百度百科
- 计算机图形学入门:什么是光线追踪?
- 搭建自己的存储服务器NAS
- windows图标文件夹_如何在Windows 10中获取Windows 7的旧文件夹图标
- android studio夜间模式,android studio怎样实现夜间模式
- 【产业互联网周报】京东数科冲击科创板,估值近2000亿元;集成电路研发商昆腾微拟科创板IPO;中芯国际科创板募资或达450亿...
- word文档内容联动
- 综合布线包括计算机网络,综合布线试题
- 使用ttf文件造成的内存泄露
热门文章
- 来与大家分享一些我们珍藏的、有力量的语句
- 数据库_SQL基本内容整理
- 牧牛区块链培训,区块链对社会生产的五大好处
- 在学习c51单片机实验七(双机通信及pcb设计)操作Keil uVision4和protus的时候遇到的两个坑
- 台式计算机内存是什么意思,内存频率是什么意思 电脑内存的工作频率是什么...
- html event 传递数据,Vue 事件的$event参数=事件的值案例
- softlayer iso_使用Softlayer Auto Scale缩放Sterling B2B Integrator
- 教你玩Robocode(4)——规则系统
- 批量写入mysql数据库的Python脚本
- 中国红薯淀粉市场供需现状调研及前景策略分析报告2022年版