我是摩卡新手,我試圖用它來測試一個簡單的React組件。如果反應組件沒有任何CSS樣式,但會拋出一個語法錯誤的測試會通過,如果內做出反應成分標籤中包含任何的className:摩卡測試失敗,由於在webpack中的css
Testing.react.js
import React from 'react';
export default class Testing extends React.Component {
render() {
return (
<section>
<form>
<input type="text" />
</form>
</section>
);
}
}
testing.jsx
import {
React,
sinon,
assert,
expect,
TestUtils
} from '../../test_helper';
import TestingSample from '../../../app/components/Testing.react.js';
describe('TestingSample component', function(){
before('render and locate element', function(){
var renderedComponent = TestUtils.renderIntoDocument(
<TestingSample />
);
var inputComponent = TestUtils.findRenderedDOMComponentWithTag(
renderedComponent, 'input'
);
this.inputElement = inputComponent.getDOMNode();
});
it('<input> should be of type "text"', function() {
assert(this.inputElement.getAttribute('type') === 'text');
});
})
測試將通過:
> mocha --opts ./test/javascripts/mocha.opts --compilers js:babel/register --recursive test/javascripts/**/*.jsx
TestSample component
✓ <input> should be of type "text"
1 passing (44ms)
我加入後的className輸入標籤的內部錯誤顯示出來:
import React from 'react';
import testingStyle from '../../scss/components/landing/testing.scss';
export default class Testing extends React.Component {
render() {
return (
<section>
<form>
<input type="text" className="testingStyle.color" placeholder="Where would you like to dine" />
</form>
</section>
);
}
}
測試結果:
SyntaxError: /Users/../../../Documents/project/app/scss/components/landing/testing.scss: Unexpected token (1:0)
> 1 | .color {
|^
2 | color: red;
3 | }
我在網上搜索,但至今沒有運氣。我錯過了什麼嗎?請幫助我或指出我正確的方向將不勝感激。 我目前使用:
節點Express服務器
陣營
陣營路由器
的WebPack
通天
摩卡
柴
興農
興農柴
您是否嘗試過webpack-require軟件包? https://github.com/petehunt/webpack-require – ctrlplusb