Refactor function to a separate file
[MAILPOET-2835]
This commit is contained in:
@ -224,7 +224,7 @@ class RoboFile extends \Robo\Tasks {
|
||||
}
|
||||
|
||||
public function testJavascript($xmlOutputFile = null) {
|
||||
$command = './node_modules/.bin/mocha --require @babel/register tests/javascript/**/*.spec.js';
|
||||
$command = './node_modules/.bin/mocha --require tests/javascript/babel_register.js tests/javascript/**/*.spec.js';
|
||||
|
||||
if (!empty($xmlOutputFile)) {
|
||||
$command .= sprintf(
|
||||
|
@ -1,11 +1,4 @@
|
||||
function asNum(num) {
|
||||
const numI = parseInt(num, 10);
|
||||
if (Number.isNaN(numI)) {
|
||||
return undefined;
|
||||
}
|
||||
return numI;
|
||||
}
|
||||
|
||||
import asNum from './server_value_as_num';
|
||||
|
||||
export default function mapFormDataAfterLoading(data) {
|
||||
return {
|
||||
|
10
assets/js/src/form_editor/store/server_value_as_num.ts
Normal file
10
assets/js/src/form_editor/store/server_value_as_num.ts
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
function asNum(num?: string): number | undefined {
|
||||
const numI = parseInt(num, 10);
|
||||
if (Number.isNaN(numI)) {
|
||||
return undefined;
|
||||
}
|
||||
return numI;
|
||||
}
|
||||
|
||||
export default asNum;
|
@ -18,7 +18,7 @@
|
||||
"autoprefixer": "postcss assets/dist/css/*.css --use autoprefixer --no-map --replace",
|
||||
"scss": "node-sass assets/css/src/ --output assets/dist/css/ --output-style compact",
|
||||
"stylelint": "stylelint --fix",
|
||||
"test": "mocha --require @babel/register tests/javascript/**/*.spec.js",
|
||||
"test": "mocha --require tests/javascript/babel_register.js tests/javascript/**/*.spec.js",
|
||||
"check-types": "tsc --noEmit",
|
||||
"storybook": "start-storybook -s ./ -p 8083",
|
||||
"build-storybook": "build-storybook"
|
||||
|
1
tests/javascript/babel_register.js
Normal file
1
tests/javascript/babel_register.js
Normal file
@ -0,0 +1 @@
|
||||
require('@babel/register')({ extensions: ['.js', '.jsx', '.ts', '.tsx'] });
|
@ -0,0 +1,19 @@
|
||||
import { expect } from 'chai';
|
||||
|
||||
import asNum from '../../../../assets/js/src/form_editor/store/server_value_as_num';
|
||||
|
||||
describe.only('Server value as num', () => {
|
||||
it('Converts string to number', () => {
|
||||
expect(asNum('4')).to.equal(4);
|
||||
expect(asNum('0')).to.equal(0);
|
||||
expect(asNum('09')).to.equal(9);
|
||||
expect(asNum('159')).to.equal(159);
|
||||
expect(asNum('-159')).to.equal(-159);
|
||||
});
|
||||
|
||||
it('Converts returns undefined', () => {
|
||||
expect(asNum('xxx')).to.be.undefined;
|
||||
expect(asNum(null)).to.be.undefined;
|
||||
expect(asNum(undefined)).to.be.undefined;
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user