Allen Yu Allen Yu
Home
  • 前端文章

    • JavaScript
  • 学习笔记

    • 《TypeScript入门教程》
GitHub (opens new window)
Home
  • 前端文章

    • JavaScript
  • 学习笔记

    • 《TypeScript入门教程》
GitHub (opens new window)
  • Statement

  • Github

  • Twitter

    • Unocss VSCode extension @wheatjs
    • Unocss soo composable @Antfu7
    • sponsor-kit @Antfu7
    • vite-plugin-inspect @Antfu7
    • parallel asynchronous @SimonHoiberg
    • magic-string-extra @Antfu7
    • new-mdn @MozDevNet
    • podcasts-list @antfu7
    • test-in-javascript @antfu7
      • 今日句子
      • 原文
      • 代码
      • 翻译
      • 单词
      • 技术 - vitest
    • Widthout screen MacBook Pro @duanrui1205
    • File Nesting Config For VSCode @antfu7
    • VueUse Released V8 @VueUse
    • TypeScript Tip Record @SimonHoiberg
    • Handle Time Traveling
    • Google 搜索小技巧
  • English
  • Twitter
2022-03-06
目录

test-in-javascript @antfu7

# 今日句子

今日Twitter

# 原文

In other Programming languages (e.g.Rust), some of them have the ability to run unit tests directly in their source file.
So I am wondering why we don't have such things in JavaScript?
What are you thoughts if we have it in @vitest_dev? 查看原文 (opens new window)

# 代码

/* /src/cool-fn.ts */
import { myAnotherFn } from './utils'
export function myCoolFunction(a, b): number {
  return a + myAnotherFn(b)
}
// test case from them
if (import.meta.vitest) {
  cons { test, describe, expect } = import.meta.vitest

  describe('my-cool-fn', () => {
    test('should work', () => {
      expect(myCoolFunction(1, 2)).toBe(3)
    })
  })
}

# 翻译

在其他编程语言中(例如 Rust),它们有的可以直接在源文件中运行单元测试。
所以我很好奇,为什么我们不能在 JavaScript 中做类似的事情?
如果我们在 @vitest_dev 中拥有它,你有什么样的想法? 查看原文 (opens new window)

# 单词

  • ability: n.能力,能够;才能,技能,本领;
  • wondering:
    • v.想知道;不知道;赶到疑惑;感到诧异;
    • adj. 感到着迷的;觉得惊奇的;好奇的;

# 技术 - vitest

vitest (opens new window) 是一个基于 Vite 的测试框架,它是非常快的!

#Twitter
Last Updated: 3/6/2022, 2:10:44 PM
podcasts-list @antfu7
Widthout screen MacBook Pro @duanrui1205

← podcasts-list @antfu7 Widthout screen MacBook Pro @duanrui1205→

最近更新
01
4 月第 2 周总结
04-17
02
工具类型
04-01
03
Google 搜索小技巧
03-28
更多文章>
Theme by Vdoing | Copyright © 2018-2022 Allen Yu
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式