Comments (4)
Happened across this issue since you are asking for input on it, so here's my input:
This API makes sense to me. At first I wondered why we don't just use .attribute()
instead of .getAttribute()
, but it is more explicit what the method does when it lives alongside .hasAttribute()
.
Where things start to get dicey (in my opinion) is when we stop looking at attributes and start looking at Vue instance properties such as props, data object properties, computed properties, methods, injected dependencies, etc. All of these things are accessed homogeneously and it's up to the developer to have an understanding of what each one is.
What that means to your proposed API is that we have to start considering if props are different from those other Vue instance properties. Do we create methods for each type? Or do we embrace Vue's harmonized instance member access somehow with a differently named API? Attributes are sufficiently different from props to warrant different treatment.
Option 1: .hasAttribute()
.getAttribute()
.hasProp()
.getProp()
.getData()
.hasData()
Option 2: .hasAttribute()
.getAttribute()
.has()
.get()
Maybe the type or location of the instance member is worth testing. Someone might want to ensure that a provided service is available on a descendant component using .getInject()
, or that something is known as a data object property as opposed to a prop, for instance. Or, maybe they don't care.
It's a tough API to nail down.
from vue-test-utils.
Hi, @Daekano.
Though Vue forces us to make each member name unique among all props & data, it's still good to be explicit to tell what we are going to test.
from vue-test-utils.
So on reflection, getProps
or get
is not a good idea. It will return an unbound value, so if the prop/ method/ data/ whatever is a function that references this
it won't behave as expected.
from vue-test-utils.
I'm going to close this for the moment. We should encourage users to use getAttribute
on the Wrapper element:
wrapper.element.getAttribute('attribute')
And for props/data:
wrapper.vm.propName
from vue-test-utils.
Related Issues (20)
- Computed value does not update when data updates
- isVisible() not seeing display: none using vitest with jsdom HOT 4
- Testing component with onBeforeRouteLeave hook raising "No active route record was found" warning HOT 1
- vue2 引入 element2. 页面存在table 表格 jest 测试报错 HOT 1
- *.svg?inline issues
- Errors in `setup()` are silent if `render()` throws an error HOT 6
- Check style changes on hover HOT 1
- setData on writable computed property does not seem to work as it does in VTU.1
- classes documentation
- Support Vue 2.7.16 HOT 2
- Vue test utils not updating template when testing composables
- TypeError: $setup.mergeProps is not a function
- Data property is already defined in Props. HOT 1
- Unable to use vitest spy within vue/nuxt 3 component methods. HOT 3
- `findComponent` doesn't find anything when using `@vue/compat` HOT 1
- Components with TS generic HOT 1
- event.keyCode is deprecated
- Change mocks mid-test
- While testing out mixins, the $refs cannot be modified and due to which the testing cannot occur.
- This import pattern causes imported component to be undefined in tests
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-test-utils.