0.1.4 • Published 1 year ago

@toolkit-js/itest v0.1.4

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

itest

Unit or Component test tool.

Features

  • ✔︎ 基于 Jest 支持单元测试
  • ✔︎ 基于 Vue Testing Library 支持 Vue2 的组件测试
  • ✔︎ 支持 jsx
  • ✔︎ 支持 TypeScript

Installation

Install itest via yarn or npm.

$ yarn add @toolkit-js/itest -D

Usage

{
  "main": "index.js",
  "scripts": {
    "test": "itest"
  }
}
# Run tests
$ yarn test

Unit Test Example

// count.js
export function add(input) {
  return input + 1;
}
// count.test.js
import { add } from './count';

it('count', () => {
  expect(add(1)).toBe(2);
});

Component Test Example

<!-- HelloWorld.vue -->
<template>
  <div>
    <h1>{{ msg }}</h1>
  </div>
</template>

<script>
  export default {
    name: 'HelloWorld',
    props: {
      msg: String,
    },
  };
</script>
// HelloWorld.test.js
import { render } from '@testing-library/vue';
import HelloWorld from './HelloWorld.vue';

test('renders props.msg when passed', async () => {
  // The render method returns a collection of utilities to query your component.
  const msg = 'new message';
  const { getByText } = render(HelloWorld, {
    props: {
      msg,
    },
  });

  // getByText returns the first matching node for the provided text, and
  // throws an error if no elements match or if more than one match is found.
  getByText(msg);
});