I use this demo for learn how to use mocha
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new.target
here is my code, (with no error)
// 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');
});
});
});
but Foo().should.throw('Foo() must be called with new');
always fail
and Foo().should.throw(/Foo\(\) must be called with new/);
fail too
or I should just don't use should
?
https://github.com/tj/should.js#throw-and-throwerror
How to I do without add this code every time? and add to npm test
var should = require('should');
var chai = require('chai');
var expect = require('chai').expect;
var assert = require('chai').assert;