Comments (5)
不是很明白你的全局方法具体是啥,Vue.use并不关心是不是npm包啊...
全局挂载就是正常挂载就行了:
https://github.com/Molunerfinn/vue-koa-demo/blob/master/test/client/login.spec.js#L31
from vue-koa-demo.
引用关系是这样的
组件b<-组件a<-全局方法
全局方法获取X属性
组件a根据X属性确定本身组件当中的某些部分是否显示
组件b引入组件a
现在的问题:
【期望】测试组件b,并且能正确断言组件b当中某个类是否存在
【测试部分代码】:
`import Vue from 'vue'
import { shallowMount } from '@vue/test-utils'
import login from '@/views/login/login.vue'
import szheader from '@/components/szHeader.vue'
const tools = require('../../src/module/tools/index.js')
Vue.use(szheader)
Vue.prototype.tools = tools
let wrapper
beforeEach(() => {
let value = {
mobile: '', // 用户输入的手机号码
graphCode: '', // 图形验证码
verifyCode: '', // 短信验证码
graphCodeImg: '', // 图形验证码url
showGraphCode: false, // 是否展示验证码
currentTimer: 60, // 收到验证码后的等待时间
timerId: '', // 监听等待时间的id
sendVerifyCodeText: '获取验证码', // 发送验证码btn按钮文案
canSendVerifyCode: true, // 是否能发送验证码
canLogin: true, // 是否能点击登录按钮
backUrl: '' // 指定的返回链接
}
wrapper = shallowMount(login)
wrapper.setData(value)
})
test('应该有一个类', () => {
const szpage = wrapper.find('.sz-page')
expect(szpage).toBeTruthy()
})
`
【报错】:组件szheader当中判断ua类型,但是读取不到ua.app属性
TypeError: Cannot read property 'app' of undefined
不知道这样的描述是否清楚
【另外】ua的获取已经做了兜底策略,如果没有获取到,或者获取到undefined,那么就默认设置{os:'',app:''}
from vue-koa-demo.
抱歉我也不太清楚为什么
from vue-koa-demo.
from vue-koa-demo.
点赞!
from vue-koa-demo.
Related Issues (20)
- Docker support HOT 2
- 新年好,楼主请帮忙,这是es6的转义导致的吗? HOT 1
- bcrypt.compareSync is not a function
- ssr分支->reademe.md 对.env配置说明有误 HOT 1
- 代理端口号出错 HOT 6
- 单元测试里面有国际化i18n 报错 HOT 1
- 运行时报错 HOT 1
- 运行时遇到一些问题 HOT 2
- 作者大大,方便交流下nginx配置吗? HOT 1
- 关于开发环境下ssr的问题 HOT 2
- ssr index.html的问题 HOT 1
- 为什么不能使用import HOT 1
- 库主是用什么版本的linux系统?安装yarn add sequelize mysql HOT 5
- 想搭建远程调试,一直不成功 HOT 7
- [单元测试] vue-router的跳转怎么验证? HOT 2
- 数据库连接报错 HOT 5
- server-entry.js 使用babel registry在生产环境是否会造成性能问题 HOT 1
- ssr webpack-hot-middleware error HOT 5
- can this framework handle image uploading and hosting? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-koa-demo.