【发布时间】:2015-04-06 17:00:30
【问题描述】:
我想为我正在构建的项目设置测试。在我能找到的示例中,他们都说包含要测试的相关代码是由 require 语句完成的:require('foo');。但是我的项目不是在模块中构建的,而是在 ES6 类中构建的,然后将其转换为 ES5 原型。
我想知道如何包含文件?
例如 ES6 类:
class Foo {
constructor() {
// do things
}
}
大致翻译为:
// ES5 compatible code is here (_classCallCheck etc).
var Foo = (function () {
function Foo() {
_classCallCheck(this, Foo);
// do things
}
}
我想知道如何将它包含在我的测试文件中:
var expect = require('chai').expect;
// how to require or whatever else here?
describe('Foo', function() {
it('creates an Foo object', function() {
var foo = new Foo({});
});
});
【问题讨论】:
标签: javascript unit-testing testing mocha.js chai