1-6 Verify Custom JavaScript Tests with Jest

Verify Custom JavaScript Tests with Jest

Up to this point we’ve created all our own utilities. As it turns out, the utilities we’ve created mirror the utilities provided by Jest perfectly! Let’s install Jest and use it to run our test!

提取码:mdij

观看视频

Code

Transcript

The testing framework we've written actually looks remarkably a lot like Jest. Rather than running node --require, and then instead of globals and so on and so forth, we could actually just use Jest directly.

If I run npx jest,

Terminal

npx jest

jest will automatically pick up our jest.test.js file based off of that convention.

jest.test.js

const {sumAsync, subtractAsync} = require('../math')

test('sumAsync adds numbers asynchronously', async () => {
  const result = await sumAsync(3, 7)
  const expected = 10
  expect(result).toBe(expected)
})

test('subtractAsync subtracts numbers asynchronously', async () => {
  const result = await subtractAsync(7, 3)
  const expected = 4
  expect(result).toBe(expected)
})

It will show us really helpful error messages, and even a code frame to show us exactly where in our code that error was thrown.

image

These are some of the things that make jest such an awesome testing framework because the error messages are so clear.

star该项目

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,484评论 0 10
  • 你把心情 都封存在玉里 那里温暖如春 更似富贵温柔乡 可蓝田的黄土地 却贫瘠如斯 一道道堎坎 如你额上的褶皱 岁月...
    伊丽苏白阅读 346评论 0 1
  • 看了很多关于《前任三》的观感,不由觉得从任何角度来看,都有着不同的道理。 有人说是孟云的错,身为男人,为什么不能去...
    倾一生白了头阅读 295评论 1 1
  • 2015年2月27日,韩城阴天,卡卡去了西安,西安正下着雪。 两天后,我和林达启程去了厦门。 岁月终将故事酿成一壶...
    连野阅读 564评论 0 0
  • 命中注定这四个字是残酷的,因为人往往在最无奈最束手无策最无能为力的时候会说这就是命。
    幼儿园东东小朋友阅读 148评论 0 1