我使用此演示来学习如何使用mocha
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new.target
这是我的代码,(没有错误)
// JavaScript source code
var should = require('should');
var chai = require('chai');
var expect = require('chai').expect;
var assert = require('chai').assert;
describe('new.target', function () {
describe('new.target in function calls', function () {
function Foo() {
if (!new.target) throw 'Foo() must be called with new';
}
it('Foo instantiated with new', function () {
(new Foo()).should.be.an.instanceof(Foo);
});
it('Foo() must be called with new', function () {
//Foo().should.throw('Foo() must be called with new');
assert.throws(Foo, 'Foo() must be called with new');
});
});
});
但 Foo().should.throw('Foo() must be called with new');
总是失败
并且Foo().should.throw(/Foo\(\) must be called with new/);
也失败了
或者我应该不使用should
?
https://github.com/tj/should.js#throw-and-throwerror
如何在不添加此代码的情况下执行此操作?并添加到npm test
var should = require('should');
var chai = require('chai');
var expect = require('chai').expect;
var assert = require('chai').assert;