Tag: expression式jestjs

是否有可能在我的Jesttesting套件中创build一个Express.js服务器?

我试图testing一个函数,使用axios从外部API获取数据。 为了让我的testing函数尽可能地接近真实的东西,我正在查询文件中的模拟数据。 Axios无法从本地文件返回数据,这是一项安全function。 所以我正在尝试的解决scheme是在我的testing套件中启动一个简单的服务器,在那里提供文件,然后运行我的testing。 我的testing套件现在看起来像这样: import React from 'react'; import {shallow} from 'enzyme'; import express from 'express'; import { getFeedId, getFeedData, reverseStop } from '../mocks/apiMock'; const app = express(); const port = 4000; app.use(express.static('../mocks/MockData.json')); app.listen(port, tests()); function tests () { it('returns the expected feed id for a given subway line', () => { expect(getFeedId('L')).toBe(2); }); […]

嘲笑笑话?

我对JS很新,但我正在尽我所能学习。 事实上,我试图嘲笑。 这是我的基类(为了testing的目的而减less): import compression from 'compression'; import express from 'express'; export default class Index{ constructor(){} spawnServer(){ console.log(express()); let app = express(); app.use(STATIC_PATH, express.static('dist')); app.use(STATIC_PATH, express.static('public')); etc… } } 这是我试图在一个单独的testing文件中实现的testing…: test('should invoke express once', () =>{ index.spawnServer(); expect(mockExpressFuncs().use.mock.calls.length).toBe(3); }) 我的问题是 – 如何使testing覆盖被testing的类的要求 – 甚至可能吗? 我希望我的索引使用express的模拟版本,其中包括express()和express.require。 我确实阅读了文档,并尝试了如下内容: const mockFunction = function() { return { use: useFn, […]