@vue/test-utils#mount TypeScript Examples

The following examples show how to use @vue/test-utils#mount. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts    From vue-hooks-form with MIT License 7 votes vote down vote up
renderHook = <Result>(
  callback: () => Result | void = () => { },
): RenderHookResult<Result> => {
  let result
  const Container = defineComponent({
    setup() {
      result = callback()
      return result
    },
    render() {
      return null
    },
  })
  mount(Container)

  return {
    result,
  }
}
Example #2
Source File: snapshot.test.tsx    From vue-request with MIT License 6 votes vote down vote up
describe('RequestConfig', () => {
  const Child = defineComponent({
    setup() {
      return () => <button>button</button>;
    },
  });
  it('RequestConfig default slots should work ', () => {
    const wrapperA = mount(
      defineComponent({
        setup() {
          return () => (
            <RequestConfig config={{ loadingDelay: 0 }}>
              this is a text
            </RequestConfig>
          );
        },
      }),
    );
    expect(wrapperA.html()).toMatchSnapshot();
    wrapperA.unmount();

    const wrapperB = mount(
      defineComponent({
        setup() {
          return () => (
            <RequestConfig config={{ loadingDelay: 0 }}>
              this is a text
              <Child />
            </RequestConfig>
          );
        },
      }),
    );
    expect(wrapperB.html()).toMatchSnapshot();
  });
});
Example #3
Source File: Alert.spec.ts    From elenext with MIT License 6 votes vote down vote up
test('props type', async () => {
  const wrapper = mount(EAlert, {
    props: {
      title: 'title',
      type: 'success',
    },
  })
  expect(wrapper.find('.el-alert').classes()).toContain('el-alert--success')
})
Example #4
Source File: NeonSkeletonLoader.spec.ts    From neon with MIT License 6 votes vote down vote up
describe('NeonSkeletonLoader', () => {
  it('renders correct number of loading bars', () => {
    // given
    const count = 5;
    const wrapper = mount(NeonSkeletonLoader, {
      propsData: { count },
    });
    // when / then
    expect(wrapper.findAll('.neon-skeleton-loader__item').length).toEqual(count);
  });
});
Example #5
Source File: index.spec.tsx    From fect with MIT License 6 votes vote down vote up
describe('AvatarGroup', () => {
  it('should be work as avatar container', () => {
    const wrapper = mount({
      render() {
        return (
          <AvatarGroup count="10">
            <Avatar text="a" stacked />
            <Avatar text="b" stacked />
          </AvatarGroup>
        )
      }
    })

    expect(wrapper.html()).toMatchSnapshot()

    expect(wrapper.find('.fect-avatar__counter').text()).toBe('+10')

    expect(() => wrapper.unmount()).not.toThrow()
  })

  it('avatar context props should be work', () => {
    const wrapper = mount({
      render() {
        return (
          <AvatarGroup count="10" stacked size="mini" isSquare>
            <Avatar text="a" />
            <Avatar text="b" isSquare={false} />
          </AvatarGroup>
        )
      }
    })

    expect(wrapper.html()).toMatchSnapshot()
  })
})
Example #6
Source File: handlers.spec.ts    From formkit with MIT License 6 votes vote down vote up
describe('vue warning interception', () => {
  it('decodes W650', () => {
    const warning = jest.fn(() => {})
    const mock = jest.spyOn(global.console, 'warn').mockImplementation(warning)
    mount(FormKitSchema, {
      props: {
        schema: ['$get(true).value'],
      },
      global: {
        plugins: [[plugin, defaultConfig]],
      },
    })
    mock.mockRestore()
    expect(warning).toBeCalledWith(
      'Schema "$get()" must use the id of an input to access.'
    )
  })
  it('decodes W651', () => {
    const warning = jest.fn(() => {})
    const mock = jest.spyOn(global.console, 'warn').mockImplementation(warning)
    mount(
      {
        template: `<h1>hi</h1>`,
        setup() {
          setErrors('nothere', {})
        },
      },
      {
        global: {
          plugins: [[plugin, defaultConfig]],
        },
      }
    )
    mock.mockRestore()
    expect(warning).toBeCalledWith(
      'Cannot setErrors() on "nothere" because no such id exists.'
    )
  })
})
Example #7
Source File: utils.ts    From vue3-gettext with MIT License 6 votes vote down vote up
mountWithPlugin = (pluginOptions: Partial<GetTextOptions>) => (componentOptions: any) => {
  const gettext = createGettext(pluginOptions);
  return mount(componentOptions, {
    global: {
      plugins: [gettext],
    },
  });
}
Example #8
Source File: VNumeric.spec.ts    From vuetify-numeric with MIT License 6 votes vote down vote up
describe('VNumeric.js', () => {
  it('renders', () => {
    const wrapper = mount(VNumeric, {
      vuetify,
      propsData: {
        value,
        useGrouping: true,
        precision,
        prefix
      }
    })
    // wrapper.nextTick()
    // const input = wrapper.element.getElementsByTagName('input')[0]
    // console.log(input)
    // // expect(input.innerText).toMatch('$1,258.00')
    expect(wrapper.html()).toMatchSnapshot()
  })
})
Example #9
Source File: useLifecycles.test.ts    From vhook with MIT License 6 votes vote down vote up
describe('test useLifecycles', () => {
  test('callback should be called when mounted or unmounted', () => {
    const onMounted = jest.fn()
    const onUnmounted = jest.fn()
    const wrapper = mount({
      template: '<div>test</div>',
      setup () {
        useLifecycles(onMounted, onUnmounted)
      }
    })
    expect(onMounted).toHaveBeenCalledTimes(1)
    wrapper.unmount()
    expect(onUnmounted).toHaveBeenCalledTimes(1)
  })
})
Example #10
Source File: CollectionList.spec.ts    From MDDL with MIT License 6 votes vote down vote up
describe('CollectionList component', () => {
  let vuetify: Vuetify

  beforeEach(() => {
    vuetify = new Vuetify()
  })

  it('exports a valid component', () => {
    const wrapper = mount(CollectionList, {
      vuetify,
      mocks: {
        $store: {
          dispatch: () => [],
          commit: () => {
            // empty
          },
        },
      },
      localVue,
    })
    expect(wrapper.html()).toBeTruthy()
  })
})
Example #11
Source File: bar.spec.tsx    From g2plot-vue with MIT License 6 votes vote down vote up
describe('BarChart', () => {
  test('should render without crashed', () => {
    mount(BarChart, {
      props: {
        data: [],
        xField: 'a',
        yField: 'b',
      },
    })
  })
})
Example #12
Source File: Alert.spec.ts    From elenext with MIT License 5 votes vote down vote up
test('create', async () => {
  const wrapper = mount(EAlert, {
    props: { title: 'title' },
  })
  expect(wrapper.find('.el-alert').classes()).toContain('el-alert')
})
Example #13
Source File: store.spec.ts    From vue3-treeview with MIT License 5 votes vote down vote up
test("Expect to create store", () => {
    const nodes = {
        id1: {
            text: "text1"
        }
    };

    const config = {
        roots: ["id1"]
    };

    const wrapper = mount({
        template: "<div></div>",
        props: ["nodes", "config"]
    }, {
        propsData: {
            nodes,
            config
        }
    });

    const id = createState(wrapper.props() as any);

    const state = states.get(id);

    expect(isRef(state.nodes)).toBe(true);
    expect(isReadonly(state.nodes)).toBe(true);
    expect(state.nodes.value.id1).toMatchObject({text: "text1"});
       
    expect(isRef(state.config)).toBe(true);
    expect(isReadonly(state.config)).toBe(true);
    expect(state.config.value).toMatchObject({roots:["id1"]});

    expect(isRef(state.focusable)).toBe(true);
    expect(state.focusable.value).toBeNull();

    expect(isRef(state.dragged)).toBe(true);
    expect(state.dragged.value).toMatchObject({
        node: null,
        element: null,
        wrapper: null,
        parentId: null
    });
});
Example #14
Source File: NeonSideNav.spec.ts    From neon with MIT License 5 votes vote down vote up
describe('NeonSideNav', () => {
  it('renders sticky slot contents', () => {
    // given
    const slotValue = 'xd';
    const wrapper = mount(NeonSideNav, {
      propsData: {},
      slots: {
        sticky: `<p>${slotValue}</p>`,
      },
    });
    // when / then
    expect(wrapper.find('.neon-side-nav__sticky p').text()).toEqual(slotValue);
  });

  it('renders scrolling slot contents', () => {
    // given
    const slotValue = 'xd';
    const wrapper = mount(NeonSideNav, {
      propsData: {},
      slots: {
        scrolling: `<p>${slotValue}</p>`,
      },
    });
    // when / then
    expect(wrapper.find('.neon-side-nav__scrolling p').text()).toEqual(slotValue);
  });

  it('renders hr when sticky and scrolling slots contents', () => {
    // given
    const slotValue = 'xd';
    const wrapper = mount(NeonSideNav, {
      propsData: {},
      slots: {
        sticky: `<p>${slotValue}</p>`,
        scrolling: `<p>${slotValue}</p>`,
      },
    });
    // when / then
    expect(wrapper.find('.neon-side-nav hr').element).toBeDefined();
  });

  it('renders full width class', () => {
    // given
    const wrapper = mount(NeonSideNav, {
      propsData: { fullWidth: true },
    });
    // when / then
    expect(wrapper.find('.neon-side-nav--full-width').element).toBeDefined();
  });
});
Example #15
Source File: index.spec.ts    From fect with MIT License 5 votes vote down vote up
describe('Avatar', () => {
  it('should be support square and circle', () => {
    const circle = mount(Avatar, {})
    expect(() => circle.unmount()).not.toThrow()
    const square = mount(Avatar, {
      props: {
        isSquare: true
      }
    })
    expect(() => square.unmount()).not.toThrow()
  })

  it('should be limited 4 characters', () => {
    const ava = mount(Avatar, {
      props: {
        text: 'XeryYue'
      }
    })
    const text = ava.find('.fect-avatar__text').text()
    expect(text.length).toBeLessThanOrEqual(3)
  })
  it('should be render as Element', () => {
    const normalAva = mount(Avatar, {
      props: {
        src: BASE_IMG_URL,
        size: 'mini'
      }
    })
    expect(normalAva.html()).toMatchSnapshot()
    const textAva = mount(Avatar, {
      props: {
        text: 'test'
      }
    })
    expect(textAva.html()).toMatchSnapshot()
  })

  it('stacked should be work', () => {
    const ava = mount(Avatar, {
      props: {
        stacked: true
      }
    })
    expect(() => ava.unmount()).not.toThrow()
  })
})