【发布时间】:2020-07-07 16:48:45
【问题描述】:
我正在使用带有以下类的 javascript:
class A {
constructor(config) {
if (_.isEmpty(config) || !_.isObject(config)) {
throw new Error('config cannot be null');
}
}
}
class B extends A {
constructor(config) {
super(config);
}
}
我正在运行以下测试:
describe('B', function () {
it('Should throw an error if instantiated without a config.', function () {
expect(function () {
const cs = new B(null);
}).to.throw();
});
});
问题是没有抛出异常,
如果我不扩展 A 类并在 B 中抛出异常,则测试通过
提前致谢
【问题讨论】:
-
这很奇怪,你确定你是在扩展同一个 A 类而不是另一个?
-
感谢您的回答!问题在于 beforeEach 函数将配置设置为不同于 null 的值。