We are using Vue Test Utils, the official unit Test utility library of vue.js.
Web site:vue-test-utils.vuejs.org/zh/
0. Run test: “test:a”: “jest./ SRC /views/tests/tenant-user-config-enum.spec.js”
1. Contains Contains you can query tags and class names. Test ('render', () => {expect(wrapper. Contains ('.tenant-small-nodes-page')).tobe (true); }); 2. It ('has a back icon', () => {expect(wrapper.text()).tocontain (' back to the list '); }); 3.. Not can be used for non-judgment conditions, async await can be written in tests asynchronously, generally clicking events, or executing methods in method, It ('not show edit Nodes in default,after click funtion,show the edit nodes', Async () => {expect(wrapper.text()).tocontain (' please select the wrapper '); // Execute the method await wrapper.vm. EditNodeFun ({}); Expect (wrapper.text()).not. ToContain (' please select the wrapper '); }); it('button click should increment the count text', async () => { expect(wrapper.text()).toContain('0') const button = wrapper.find('button') await button.trigger('click') Expect (wrapper.text()).tocontain ('1')}) 4. () => { expect(wrapper.vm.deleteEmpty([{ text: '' }, { text: '23' }], "text")).toEqual([{ text: '23' }]); }); 5. At the top you can declare fake router and route in use below, this is fake, not real!!Copy the code
it('back funtion is succuss,router push is success, page go to "/" path', Async () => {// execute method await wrapper.vm.goBackList({}); expect(wrapper.vm.$router.length > 0).toBe(true); expect(wrapper.vm.$router[0].path === '/').toBe(true); console.log(wrapper.vm.$route.path, wrapper.vm.$router, wrapper.vm.$router[0].path, 22); });Copy the code