Я создаю небольшую библиотеку, используя Nodejs, и у меня есть некоторые проблемы с тестированием мокко и чаи.Единичное тестирование мокко chai с аргументами
Моя проблема возникает, когда я пытаюсь шпионить за функцией и ожидать, что она была вызвана с некоторыми параметрами.
Фактически, когда я регистрирую, параметры, переданные функции, являются хорошими. Но тест терпит неудачу снова и снова.
Вот что я м тестирование:
import callback from './callback'
/**
* Connect the express routes with the injector directly inside of the app
* @param {Object} app An express application, or an application that has the same api
* @param {Object} injector An injector with the interface of deepin module
* @param {Object} parser An object with the interface of route-parser module
*/
const expressKonnector = (app, injector, parser) => {
const routes = parser.parseRoutes()
for (const route of routes) {
app[route.method](route.pattern, callback(injector, route))
}
}
export default expressKonnector
Вот обратный вызов зависимый модуль:
import callbackRender from './callbackRender'
import { HttpRequest } from 'default-http'
export default (injector, route) => {
const ctrl = injector.get(route.controller)
return (request, response) => {
const result = ctrl[route.controllerMethod](new HttpRequest())
if (result.then) {
return result.then(res => callbackRender(res, response))
} else {
callbackRender(result, response)
}
}
}
А вот неисправный тест:
it('should call the app.get method with pattern /users/:idUser and a callback',() => {
const spy = chai.spy.on(app, 'get')
const routes = routeParser.parseRoutes()
expressKonnector(app, injector, routeParser)
expect(spy).to.have.been.called.with('/users/:idUser', callback(injector, routes[1]))
})
У меня есть следующий стек, когда испытание не выполнено:
ExpressKonnector ExpressKonnector should call the app.get method with pattern /users/:idUser and a callback:
AssertionError: expected { Spy, 3 calls } to have been called with [ '/users/:idUser', [Function] ]
at Context.<anonymous> (C:/Project/javascript/express-konnector/src/test/expressKonnector.spec.js:176:43)
Если вы хотите иметь больше деталей, или просто запустить "NPM установить тестовую команду & & НПМ", вы можете иметь модуль на этой GitHub (Dev филиал):
https://github.com/Skahrz/express-konnector