【发布时间】:2020-03-09 17:32:28
【问题描述】:
我的项目中有这样的结构
|...
|Utils
| Utils.js
| Utils.test.js
|...
在Utils.js我有func,我要测试:
export const getSurroundingCells = (numRows, numCols, shipPositions) => {
...
// some logic that calls cellIsSuitable()
...
const cellIsSuitable = (position, shipPositions) => {
...
// some logic that uses numRows, numCols
...
}
}
当我想通过Jest 和Utils.test.js 测试它时:
import {getSurroundingCells} from "./Utils";
const shipPositions = [[1, 1], [1, 2], [1, 3]];
const expectedSurroundingCells = [[2, 1], [2, 0], [1, 0], [0,0], [0,1], [0,2], [2,2]];
test('takes positions and returns surrounding cells', () => {
expect(getSurroundingCells(10, 10, shipPositions)).toBe(expectedSurroundingCells);
});
我明白了:
ReferenceError: cellIsSuitable 未定义
如何强制Jest 看到我的嵌套函数cellIsSuitable?
附:我的项目自举with create-react-app。
【问题讨论】:
标签: javascript jestjs create-react-app