@eplata/utils
Version:
Modulo que contiene funciones generales para tratamiento de datos.
50 lines (36 loc) • 1.53 kB
JavaScript
const chai = require('chai');
const proxyquire = require('proxyquire').noCallThru();
const sinon = require('sinon');
const faker = require('faker');
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
const expect = chai.expect;
describe('Utils Module::string - tryParseInt() Unit Test', () => {
describe('Case Success - Get integer value from string value.', () => {
const strMock = '123456';
const tryParseIntFunction = require('./../../src/string/try-parse-int');
const result = tryParseIntFunction(strMock);
it(`Should return a integer.`, () => {
expect(result).to.be.a('number');
});
});
describe('Case Success - Get string value when cant parse string value', () => {
const strMock = '123456abc';
const tryParseIntFunction = require('./../../src/string/try-parse-int');
const result = tryParseIntFunction(strMock);
it(`Should return a integer.`, () => {
expect(result).to.be.a('string');
});
});
describe('Case Exception - Get exception when cant parse string value and strict flag is true', () => {
const strMock = '123456abc';
const tryParseIntFunction = require('./../../src/string/try-parse-int');
try {
const result = tryParseIntFunction(strMock, true);
} catch (error) {
it(`Should thow exception.`, () => {
expect(error).to.be.a('error');
});
}
});
});