使用了导入映射 · Cocos Creator,将 project/assets/scripts 映射为 scripts/,那么在业务脚本project/assets/scripts/BusinessExample.ts 就可以使用裸说明符导入依赖模块,如下
import AnotherBusinessExample from 'scripts/AnotherBusinessExample'
export class BusinessExample {
...
}
希望基于 jest 对业务逻辑进行测试,在 project/tests/BusinessExample.test.ts 使用相对说明符导入目标模块,如下
import { BusinessExample } from '../assets/scripts/BusinessExample'
test('test BusinessExample', () => { ... })
这里会出现一个问题,裸说明符 'scripts/AnotherBusinessExample' 无法识别。