Sono nuovo a Mocha e sto cercando di usarlo per testare un semplice componente React. Il test passerebbe se il componente reagire non ha stile CSS, ma getta un errore di sintassi se il tag all'interno del componente Reagire contiene alcun className:Test di Mocha falliti a causa di css nel pacchetto web
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');
});
})
il test sarebbe passato:
> 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)
dopo ho aggiunto il className all'interno del tag input un errore si presenta: risultato
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>
);
}
}
prova:
SyntaxError: /Users/../../../Documents/project/app/scss/components/landing/testing.scss: Unexpected token (1:0)
> 1 | .color {
|^
2 | color: red;
3 | }
Ho cercato online, ma senza fortuna finora. Mi sto perdendo qualcosa? Per favore aiutami o indicami la giusta direzione sarebbe molto apprezzato. Attualmente sto usando:
Nodo Express Server
Reagire
React-router
Webpack
Babel
Mocha
Chai
Sinon
Sinon-Chai
Hai provato pacchetto web-require? https://github.com/petehunt/webpack-require – ctrlplusb