I am unit testing and will briefly layout the structure of the code. 1. currency.js which has currencies in an object which looks like this:
module.exports = {
'United States': 'USD',
'India': 'Rupee',
'Mexico': 'Peso',
}
CurrencyField which needs the currency.js to print it as an option list:
const React = require('react'); const currency = require('somepath/currency');
const CurrencyField = ({onCurrencyNameSet, currencyName}) => { const currencyOptions = ['Select Currency'].concat(Object.values(currency)).map((thiscurrency) => <option key={thiscurrency}>{thiscurrency}</option> ); return ( <fieldset className="currency-form-group"> <label className="currency-form-group-label">Country</label> <select onChange={onCurrencyNameSet} className="currency-form" value={currencyName}> {currencyOptions} </select> </fieldset> ); };
I then have a PaymentForm.js which uses the currency as one of its fields.
class PaymentForm extends React.Component {
// some events. render() {
return (
// many things
<CurrencyField onCurrencyNameSet={this.onFieldSet('currency')} currencyName={this.state.currencyName} />
// many other things
)
} }
Then I have a unit test framework like this:
describe('when rendering currency', function() { beforeEach(function() { this.wrapper = Enzyme.mount(React.createElement(PaymentForm, {some params})); });
Trouble: undefined is not a constructor (evaluating 'Object.values(currency)')
Any ideas how to resolve this issue ?
This syntax is invalid:
Object.values() is a standalone function call. You can't combine it in arrays with dot notation like this.
Did you mean?