node.js - Export Function From Test file and use it in component file?
问题描述
I am new in Angular and NodeJS UTs. I have a function in test file and I have exported that function to use it in another file but once I call it from another file then I am receiving an error of describe block. Here is my code:
abc.controller.ts
export function mockGetAppByName(exists: boolean, error?: boolean) {
// some execution
}
mock.app.ts
import { mockGetAppByName} from '../../test/api/abc/abc.controller.test';
//Called function below in some other function
mockGetAppByName(true);
When I run command npm start
It throws below error. If I does not export it then it works fine...When I export and import this function in another file then also I am not receiving any error...BUT...once I call that function in my code then it throws an error. It does not allow my server to start and it keep throwing error.
ERROR
C:\Ambuj Khanna\Project\STA_Console\STAConsole\server\tmp\test\api\action\action.controller.test.js:194 describe('ActionController', () => { ^
ReferenceError: describe is not defined at Object. (C:\Ambuj Khanna\Project\project\server\tmp\test\api\action\abc.controller.test.js:194:1) ←[90m at Module._compile (internal/modules/cjs/loader.js:955:30)←[39m ←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)←[39m ←[90m at Module.load (internal/modules/cjs/loader.js:811:32)←[39m ←[90m at Function.Module._load (internal/modules/cjs/loader.js:723:14)←[39m ←[90m at Module.require (internal/modules/cjs/loader.js:848:19)←[39m ←[90m at require (internal/modules/cjs/helpers.js:74:18)←[39m at Object. (C:\Ambuj Khanna\Project\project\server\tmp\src\mock\mock.application.js:10:34) ←[90m at Module._compile (internal/modules/cjs/loader.js:955:30)←[39m ←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)←[39m ←[90m at Module.load (internal/modules/cjs/loader.js:811:32)←[39m ←[90m at Function.Module._load (internal/modules/cjs/loader.js:723:14)←[39m ←[90m at Module.require (internal/modules/cjs/loader.js:848:19)←[39m ←[90m at require (internal/modules/cjs/helpers.js:74:18)←[39m at Object. (C:\Ambuj
Khanna\Project\STA_Console\STAConsole\server\tmp\src\mock\index.js:5:28) ←[90m at Module._compile (internal/modules/cjs/loader.js:955:30)←[39m ←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)←[39m ←[90m at Module.load (internal/modules/cjs/loader.js:811:32)←[39m ←[90m at Function.Module._load (internal/modules/cjs/loader.js:723:14)←[39m ←[90m at Module.require (internal/modules/cjs/loader.js:848:19)←[39m ←[90m at require (internal/modules/cjs/helpers.js:74:18)←[39m at Object. (C:\Ambuj Khanna\Project\STA_Console\STAConsole\server\tmp\src\app.js:7:14)
解决方案
推荐阅读
- flutter - Dart:标识符之前与之后的感叹号
- python - 两个名称非常相似的列表的模糊匹配
- python - 如何找到元素之间的差异,忽略 NA 值
- python - Have gradient colours in sns.pairplot for one column of dataframe so that I can see which datapoints are connected to each other
- unity3d - 如何在具有特定 android 版本的 android 模拟器上测试 Unity 游戏?
- qt - 如何使用 yocto 构建简单的 qt 应用程序?
- linux - Xbindkeys 绑定鼠标按键来模拟 Super Key
- python - django ORM函数如何与db交互并解析sql代码?
- ios - MS Teams iOS 应用程序:从已发送的英雄卡中删除元素
- powerbi - 创建一个基于与长表不同的计数结果取平均值的度量?