All Downloads are FREE. Search and download functionalities are using the official Maven repository.

utils.evalExpression.test.js Maven / Gradle / Ivy

The newest version!
import evalExpression, { parseExpression } from './evalExpression'

describe('Тесты evalExpression', () => {
    it('parseExpression вернет expression', () => {
        expect(parseExpression('`testExpression`')).toEqual('testExpression')
        expect(parseExpression('`\'Имя:\' + name`')).toEqual('\'Имя:\' + name')
    })

    it('parseExpression вернет false', () => {
        expect(parseExpression(0)).toEqual(false)
        expect(parseExpression('`not valid expression')).toEqual(false)
    })

    it('evalExpression вернет expression', () => {
        expect(
            evalExpression(parseExpression('`a + b`'), {
                a: 3,
                b: 4,
            }),
        ).toEqual(7)
    })

    it('evalExpression вызовет исключение', () => {
        expect(
            evalExpression(parseExpression('`unknownValue`'), {
                value: 'VALUE',
            }),
        ).toEqual(undefined)
    })
})




© 2015 - 2024 Weber Informatics LLC | Privacy Policy