Skip to content

Commit

Permalink
Better handling of missing imports and mispelled editor options
Browse files Browse the repository at this point in the history
  • Loading branch information
securingsincity committed May 28, 2017
1 parent 986bd70 commit 3ce5144
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const themes = [

languages.forEach((lang) => {
require(`brace/mode/${lang}`)
require(`brace/snippets/${lang}`)
})

themes.forEach((theme) => {
Expand Down
1 change: 1 addition & 0 deletions example/split.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const themes = [

languages.forEach((lang) => {
require(`brace/mode/${lang}`)
require(`brace/snippets/${lang}`)
})

themes.forEach((theme) => {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"nyc": "^10.3.2",
"react-addons-test-utils": "^15.5.1",
"rimraf": "^2.5.2",
"sinon": "^2.2.0",
"sinon": "^2.3.2",
"webpack": "^2.5.1",
"webpack-dev-server": "^2.4.5"
},
Expand Down Expand Up @@ -103,4 +103,4 @@
"url": "https://opencollective.com/react-ace",
"logo": "https://opencollective.com/opencollective/logo.txt"
}
}
}
2 changes: 2 additions & 0 deletions src/ace.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export default class ReactAce extends Component {
const option = editorOptions[i];
if (availableOptions.hasOwnProperty(option)) {
this.editor.setOption(option, this.props[option]);
} else if (this.props[option]) {
console.warn(`ReaceAce: editor option ${option} was activated but not found. Did you need to import a related tool or did you possibly mispell the option?`)
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/split.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export default class SplitComponent extends Component {
const option = editorOptions[i];
if (availableOptions.hasOwnProperty(option)) {
editor.setOption(option, this.props[option]);
} else if (this.props[option]) {
console.warn(`ReaceAce: editor option ${option} was activated but not found. Did you need to import a related tool or did you possibly mispell the option?`)
}
}
this.handleOptions(this.props, editor);
Expand Down
10 changes: 9 additions & 1 deletion tests/src/ace.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import ace from 'brace';
import { mount } from 'enzyme';
import AceEditor from '../../src/ace.jsx';
import brace from 'brace'; // eslint-disable-line no-unused-vars

describe('Ace Component', () => {

// Required for the document.getElementById used by Ace can work in the test environment
Expand All @@ -21,6 +20,14 @@ describe('Ace Component', () => {
expect(wrapper).to.exist;
});

it('should trigger console warn if editorOption is called', () => {
const stub = sinon.stub(console, 'warn');
const wrapper = mount(<AceEditor enableBasicAutocompletion={true} />, mountOptions);
expect(wrapper).to.exist;
expect(console.warn.calledWith('ReaceAce: editor option enableBasicAutocompletion was activated but not found. Did you need to import a related tool or did you possibly mispell the option?') ).to.be.true;
stub.restore();
});

it('should render without problems with defaults properties, defaultValue and keyboardHandler', () => {
const wrapper = mount(<AceEditor
keyboardHandler="vim"
Expand Down Expand Up @@ -399,6 +406,7 @@ describe('Ace Component', () => {
expect(onFocusCallback.callCount).to.equal(1);
});


});

});
10 changes: 9 additions & 1 deletion tests/src/split.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Split Component', () => {
};

describe('General', () => {

sinon.restore()
it('should render without problems with defaults properties', () => {
const wrapper = mount(<SplitEditor />, mountOptions);
expect(wrapper).to.exist;
Expand All @@ -28,6 +28,14 @@ describe('Split Component', () => {
expect(beforeLoadCallback.getCall(0).args[0]).to.deep.equal(ace);
});

it('should trigger console warn if editorOption is called', () => {
const stub = sinon.stub(console, 'warn');
const wrapper = mount(<SplitEditor enableBasicAutocompletion={true} />, mountOptions);
expect(wrapper).to.exist;
expect(console.warn.calledWith('ReaceAce: editor option enableBasicAutocompletion was activated but not found. Did you need to import a related tool or did you possibly mispell the option?') ).to.be.true;
stub.restore();
});

it('should set the editor props to the Ace element', () => {
const editorProperties = {
react: 'setFromReact',
Expand Down

0 comments on commit 3ce5144

Please sign in to comment.