当console.log时,mock-fs test在jest中失败

时间:2018-04-19 00:00:30

标签: javascript node.js filesystems jestjs fs

出于某种奇怪的原因,当我尝试console.log test import fs from 'mz/fs' import mockFs from 'mock-fs' beforeEach(async () => { mockFs({ '/dir': { '.pkgrc': JSON.stringify([]) } }) }) afterEach(async () => { mockFs.restore() }) test('readdir callback', (done) => { fs.readdir('/dir', (err, res) => { if (err) throw err expect(res).toEqual(['.pkgrc']) done() }) }) test('readdir promise', async () => { const res = await fs.readdir('/dir') expect(res).toEqual(['.pkgrc']) }) test('readdir promise', async () => { const res = await fs.readdir('/dir') console.log('hi') expect(res).toEqual(['.pkgrc']) }) 使用jest它失败时,我不知道为什么会发生这种情况。

是否有特定原因发生这种情况?我该如何预防?

mock-fs

ENOENT, no such file or directory '/home/runner/node_modules/callsites'

      at Binding.<anonymous> (node_modules/mock-fs/lib/binding.js:1060:13)
      at maybeCallback (node_modules/mock-fs/lib/binding.js:42:17)
      at Binding.Object.<anonymous>.Binding.lstat (node_modules/mock-fs/lib/binding.js:1057:10)
      at _callee4$ (test.js:91:19)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:296:22)
      at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:114:21)
      at step (test.js:13:191)
      at test.js:13:361

以下是具体错误:

{{1}}

0 个答案:

没有答案