Skip to main content

Posts

Showing posts with the label jest

circleci - action - jest

https://github.com/testing-library/react-hooks-testing-library/issues/151 TypeError: Cannot read property 'current' of undefined "react": "^16.9.0", "react-test-renderer": "^16.9.0", "@testing-library/react": "^9.1.3", "react-dom": "^16.9.0",

window.URL.createObjectURL is not (yet) available in jest-dom - testing scenario

Since  window.URL.createObjectURL  is not (yet) available in jest-dom, you need to provide a mock implementation for it. Don't forget to reset the mock implementation after each test. describe ( "your test suite" , () => { window . URL . createObjectURL = jest . fn (); afterEach (() => { window . URL . createObjectURL . mockReset (); }); it ( "your test case" , () => { expect ( true ). toBeTruthy (); }); });

vue test: func() = 0% html().toContain

need test default props  without passing any props test ( 'required props' , () => { const wrapper = mount ( Component ) expect ( wrapper . props (). backgroundColor ). toBeTruthy () expect ( wrapper . props (). step ). toBeTruthy () expect ( wrapper . props (). assignedTo ). toBeTruthy () expect ( wrapper . props (). meetWith ). toBeTruthy () expect ( wrapper . props (). statuses ). toBeTruthy () expect ( wrapper . props (). submittable ). toBeTruthy () expect ( wrapper . props (). editable ). toBeTruthy () expect ( wrapper . props (). description ). toBeTruthy () const instructions = wrapper . props (). instructions expect ( instructions ). toBeTruthy () instructions . forEach ( e => { expect ( e . title ). toBeTruthy () expect ( e . type ). toBeTruthy () }) expect ( wrapper . html ()). toContain ( '<v-treeview-stub active="uuid-4"' )

jest - run test on individual file - and what need test to Vue file - test vue - vue-test-utils.vuejs.org

test vue: https://vue-test-utils.vuejs.org/api/wrapper/#isempty yarn test --testPathPattern=".*UsersTree.test.js" snapshot: https://jestjs.io/docs/en/snapshot-testing For VUE: https://vue-test-utils.vuejs.org/guides/#getting-started 1. Visuals expect(wrapper.element).toMatchSnapshot() expect(wrapper.html()).toContain('primary--text') 2. Computed expect(wrapper.vm.items[0]).toHaveProperty('name', 'FreshinUp') 3. method const wrapper = shallowMount(Component, { propsData: { } }) wrapper.setData({ }) await wrapper.vm.$nextTick() expect(wrapper.html()).toContain('xxx') })