• Stars
    star
    339
  • Rank 124,367 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ¦₯ Be lazy, write simple tests in comments.

Typescript Expect Plugin

npm mit license CI Gitter twitter

Be lazy, write simple tests in comments.

Editor support

βœ… VS Code - flawlessly works in Problems panel.

⏹ Sublime Text - could not get it to work but it might be possible.

❔ Atom - not tested.

β›” tsc - plugins are disabled during build. It should work with webpack ts loader.

Quick start

npm install typescript-expect-plugin
  1. Add plugin to tsconfig.json:
{
  "compilerOptions": {
    "plugins": [{ "name": "typescript-expect-plugin" }]
  },
}
  1. Change VS Code typescript to workspace version:

Usage

WARNING

⚠Tests are executed after each file change - not save. Be careful if you're going to test functions that remove or change files in your local system


This plugin adds support for @expect JSDoc tag. It has the following usage pattern:

/**
 * @expect [PARAMS] CONDITION CONDITION_PARAMETER
 */
  • [PARAMS] - for example [2, 4] will spread two arguments to tested function.
  • CONDITION - check function from jest expect library. Use ctrl+space to see autocomplete suggestions.
  • CONDITION_PARAMETER - argument passed to CONDITION function.

Examples

/**
 * @expect [2, 4] toBe 6
 * @expect [2, 2] toBeGreaterThan 3
 * @expect [2, 2] toBeLessThan 3
 * @expect [2, 22] toEqual 24
 */
export function sum(a: number, b: number) {
  return a + b;
}

/**
 * @expect [[2, 4, 8], 4] toBeTruthy
 * @expect [[2, 4, 8], 12] toBeFalsy
 */
export function has(haystack: any[], needle: any) {
  return haystack.includes(needle);
}

/**
 * @expect [[2, 8], [9, 12]] toEqual [2, 8, 9, 12]
 */
export function join(arr1: any[], arr2: any[]) {
  return [...arr1, ...arr2];
}

/**
 * @expect [{"firstName": "John"}, "lastName", "Doe"] toHaveProperty "lastName", "Doe Doe"
 */
export function withProp(obj: Record<string, any>, key: string, value: any) {
  return {...obj, [key]: value}
}

Test objects

Test arrays

Author

Hey there, I'm Kasper. If you wish to get notified about more cool typescript or react projects/tips you can follow me on twitter.

twitter

More Repositories

1

Editr.js

✏ HTML, CSS and JavaScript playground
JavaScript
1,308
star
2

chalk.ist

πŸ“· Create beautiful images of your source code
Vue
928
star
3

snatch

πŸ“‹ Beautiful clipboard manager for Windows
C#
269
star
4

cssParentSelector

CSS4 parent selector based on jQuery
CSS
215
star
5

behavior-tree

🌲 Manage React state with Behavior Trees
TypeScript
114
star
6

eslint-plugin-tailwind

ESLint rules for Tailwind CSS
JavaScript
100
star
7

twix

Style React components with TailwindCSS
TypeScript
95
star
8

iridium

πŸ’Ž VS Code extensions
Vue
71
star
9

vscode-extension-figma

Figma extension for VS Code
TypeScript
66
star
10

zen-form

Add distraction-free mode for forms
CSS
60
star
11

esuna

JavaScript
31
star
12

Garuda

A simple theme for GitHub Pages
JavaScript
18
star
13

snippets

Usefull JS, HTML, CSS and PHP snippets
JavaScript
12
star
14

react-typescript-monorepo

Learn how to manage React components within monorepo using only Typescript
TypeScript
12
star
15

figma-render

Render Figma document into HTML content
TypeScript
9
star
16

storybook-circleci-github-deployments

Learn how to host Storybook with CircleCI and Github Deployments
Shell
6
star
17

react-preset

βš› Smash your props into single preset prop
TypeScript
5
star
18

sauron

One build system to manage all your HTML, CSS, JS projects
CSS
4
star
19

figma-types

TypeScript definitions for Figma API responses
4
star
20

esuna-snippets

Snippets for Esuna Framework
2
star
21

dragToIncDec

Change input value by dragging label.
JavaScript
2
star
22

iPreload

jQuery image preloader
JavaScript
1
star
23

kasper.io

My blog
CSS
1
star
24

console2-flatland

Flatland colors for Console2
1
star
25

l4-title

Laravel 4 version of https://github.com/mywizz/title-for-laravel
PHP
1
star
26

json-wasm

TypeScript
1
star
27

vscode-npm-website

TypeScript
1
star
28

areYouSure

jQuery confirmation plugin
JavaScript
1
star
29

vitesse-motion-ssg-bug

TypeScript
1
star
30

codesandbox-template-remix

Remix template for CodeSandbox Projects
TypeScript
1
star
31

idered.github.com

My website
CSS
1
star
32

firo

SCSS framework to manage RWD fluently.
CSS
1
star
33

json-to-jsdoc

TypeScript
1
star
34

svelte-kit

Svelte
1
star