Files
piratepoet/mailpoet/tests/javascript/form-editor/store/server-value-as-num.spec.ts
Rostislav Wolny 1d32461b3d Workaround for the issue with chai v5 and ES modules
I couldn't make it work with the Babel loader. There is a possible
solution using ts-node as a loader. I didn't want to install another
package, so I chose a different workaround.
mocha-env.mjs is processed as a module thanks to the suffix, and it
sets chai. expect globally, and then I updated tests to use the global expect.

Please see https://github.com/chaijs/chai/issues/1568
[MAILPOET-6008]
2024-06-19 12:12:59 +02:00

18 lines
552 B
TypeScript

import { asNum } from '../../../../assets/js/src/form-editor/store/server-value-as-num';
describe('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;
});
});