找不到模块'它'当用摩卡/柴测试时

Cannot find module 'it' when testing with mocha/chai

本文关键字:测试 摩卡 模块 找不到      更新时间:2023-09-26

我有一个简单的测试

import {topNavigationLinks} from './navigation-links.js';
import {assert,should,expect=} from 'chai';
import {mocha} from 'mocha';

describe('Navigation Links', () => {
    it('should have the right value', function () {
      expect(topNavigationLinks(123).to.equal([]));
    });
});

但我一直收到这个错误

Error: Cannot find module 'it'

有线索吗?

您在测试文件中不需要mocha

import * as mocha from 'mocha';

编辑

您也不应该在mocha 中使用箭头函数

错误在于将node_modules作为mocha脚本的一部分。所以它检查了所有的node_module,显然没有找到it语句。删除它的