类名:Notification.ts
class Notification {
constructor() {}
public validateTempalte() {
return true;
}
private replacePlaceholder() {
return true;
}
}
单元测试:
import {Notification} from 'Notification';
import * as chai from "chai";
describe("Notification", function(){
describe('#validateTempalte - Validate template', function() {
it('it should return success', function() {
const result = new Notification()
chai.expect(result.validateTempalte()).to.be.equal(true);
});
});
describe('#replacePlaceholder - Replace Placeholder', function() {
it('it should return success', function() {
const result = new Notification()
// As expected getting error "Private is only accessible within class"
chai.expect(result.replacePlaceholder()).to.be.equal(true);
});
});
});
作为一种解决方法,目前我正在将函数replacePlaceholder的访问说明符更改为public。但我不认为这是一个有效的方法。
作为一种临时解决方法,目前我正在将函数replacePlaceholder的访问修饰符更改为public。但我并不认为这是一个恰当的做法。
(Two possible translations depending on the context.)