Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
474 views
in Technique[技术] by (71.8m points)

unit testing - Jest [vue-test-utils]: name is deprecated and will be removed in the next major version

I'm writing a Jest test file within Vue and i'm receiving the following warning:

[vue-test-utils]: name is deprecated and will be removed in the next major version. (https://vue-test-utils.vuejs.org/api/wrapper/name.html)

My test should check if certain properties are rendered:

describe("Stock", () => {
  it("should render correct symbol, name and quantity", () => {
    const stock = {
      name: "Apple",
      price: 220,
      quantity: 5
    };
    const wrapper = mount(Stock, {
      propsData: {
        stock
      }
    });
    const name = wrapper.find("[data-testid='stock-name']");
    expect(name.text()).toEqual(stock.name);
  });
})

My HTML:

<h3 class="card-title">
  <span data-testid="stock-name">
     {{ stock.name }}
  </span>
</h3>

How can I solve this warning? Or what is another way to test if a certain element contains a certain prop?

question from:https://stackoverflow.com/questions/66059451/jest-vue-test-utils-name-is-deprecated-and-will-be-removed-in-the-next-major

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For your exact usage you can use: props

import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'

const wrapper = mount(Foo, {
  propsData: {
    bar: 'baz'
  }
})
expect(wrapper.props().bar).toBe('baz')
expect(wrapper.props('bar')).toBe('baz')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...