I am trying simple test cases using mocha framework
I have written simple typescript
class Rectangle {
constructor(width, height) {
this.width = width;
this.height = height;
}
get height() {
return this.height;
}
set height(value) {
if (typeof value !== 'number') {
throw new Error('"height" must be a number.');
}
this.height = value;
}
get width() {
return this.width;
}
set width(value) {
if (typeof value !== 'number') {
throw new Error('"width" must be a number.');
}
this.width = value;
}
get area() {
return this.width * this.height;
}
get circumference() {
return 2 * this.width + 2 * this.height;
}
}
var rectangle= new Rectangle(10,20);
module.exports = Rectangle;
but when trying to write test case as below:
"use strict"
require('babel-register')({
presets: ['es2015']
});
// Import chai.
import * as chai from 'chai';
var path = require('path');
// Import the Rectangle class.
let Rectangle = require(path.join(__dirname, '..', 'rectangle.js'));
const should = chai.should;
var expect = require('chai').expect;
describe('Rectangle', () => {
describe('#width', () => {
let rectangle;
beforeEach(() => {
// Create a new Rectangle object before every test.
rectangle = new Rectangle(10, 20);
});
it('returns the width', () => {
// This will fail if "rectangle.width" does
// not equal 10.
rectangle.width.should.equal(10);
});
});
});
but the test case is failing
I dont understand the error here
Any help would be appreciated
Aucun commentaire:
Enregistrer un commentaire