0
'use strict';
/**
* PortalHTML.js
*/
import SingleContextHTML from './SingleContextHTML';
import MultiContextHTML from './MultiContextHTML';
export default class PortalHTML{
constructor (type) {
switch(type) {
case "1":
this.portalStrategy = new SingleContextHTML();
break;
default:
this.portalStrategy = new MultiContextHTML();
break;
}
}
render (...args) {
this.portalStrategy.renderHTML(args);
}
_strategyPeak(){
return this.portalStrategy.constructor.name;
}
}
/**
* SingleContextHTML.js
*/
'use strict';
import PortalHTMLStrategy from './PortalHTMLStrategy';
export default class SingleContextHTML extends PortalHTMLStrategy {
constructor(){
super()
}
renderHTML(args){}
}
/**
* Multi.js (same as single) ^^ above
*/
/**
* PortalHTMLStrategy.js
*/
'use strict';
export default class PortalHTMLStrategy{
constructor(){}
renderHTML(args){}
}
/**
* Tester Mocha and Chai
*/
'use strict';
import PortalHTML from "./PortalHTML";
import chai from 'chai';
let basicPortalHTMLTest =() => {
let singleContextHTML = new PortalHTML("1");
let multiContextHTML = new PortalHTML("multi");
describe('PortalHTML: Initialization of PortalHTML',() => {
it('Should be an instance of class SingleContextHTML', (done) => {
chai.expect(singleContextHTML._strategyPeak()).to.equal('SingleContextHTML');
done();
});
it('Should be an instance of MultiContextHTML', (done) => {
chai.expect(singleContextHTML._strategyPeak()).to.equal('MultiContextHTML');
done();
});
});
};
basicPortalHTMLTest();
コンストラクタではありませんが、私はモカと私のテストスクリプトを実行した後で次のように述べてエラーに実行しています。種類エラーは、私は戦略パターンの実装をテストしようとしています
私はnode6と、次のバベルのパッケージを使用していますvar singleContextHTML = new _PortalHTML2.default("1");
^
TypeError: _PortalHTML2.default is not a constructor
:
"babel-cli": "^6.14.0",
"babel-core": "^6.17.0",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.16.0",
"babel-preset-react": "^6.11.1",
"babel-preset-stage-2": "^6.11.0"
を私の周り半日のためにこれをデバッグしようとしています。誰かがすぐに私がやっている間違ったことを見たら、私はと非常にに感謝します。
'PortalHTMLからPortalHTMLをインポートすると、間違ったモジュール識別子が含まれているように見えます。 –
あなたは 'from"を意味しました./ProtalHTML "'? – azium
私の実際のコードでは、このおもちゃの例では、ディレクトリ構造が正しいです。混乱を避けるために更新しました。申し訳ありません – moon