javascript - 有没有办法使用 Jasmine 在 NodeJs 上对 es6 模块进行单元测试?
问题描述
我一直在研究这个几天,并没有发现任何有用的东西。
具体来说,我不想要的是将我的源代码转换为 es6 以外的东西并对其进行测试。
// Class1.js
// The use of 'export' makes this an es6 module.
export class Class1 {
getValue() {
return 42;
}
}
// Class1.spec.js
// Jasmine imports its spec files using CommonJS 'require'
// Therefore this import will not work under NodeJs and will fail with the error that
// 'import' cannot be used in a CommonJS module.
import { Class1 } from './Class1';
describe('Class1', function() {
it('getValue returns 42'), function() {
let c1 = new Class1();
expect(c1.getValue()).toBe(42);
});
});
解决方案
推荐阅读
- java - 如何使用两个不同长度的数组在表中打印值
- tensorflow - Tensorflow memory consumption is different on VM
- python - Co occurance matrix for tfidf vectorizer for top 2000 words
- java - The HTTP response from the server [200] did not permit the HTTP upgrade to WebSocket
- sql - How to dynamically create and populate a local temp table (when the table headers are unknown)?
- c# - Prevent default pdf reader open after call PrintTo c#
- node.js - 使用 Chrome、webRoot 属性调试 VS Code
- multithreading - 带有 Observables 的 ThreadpoolExecutor
- json - Python解析字符串,列表
- android - 什么是已弃用的 StaticLayout 的替代品