Skip to content

Commit

Permalink
test: add test for string utils
Browse files Browse the repository at this point in the history
  • Loading branch information
wxsms committed Dec 10, 2021
1 parent 3acfda0 commit b452445
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as directives from './directives';
import * as services from './services';
import locale from './locale';

const install = (app, options = {}) => {
export const install = (app, options = {}) => {
// Setup language, en-US for default
locale.use(options.locale);
locale.i18n(options.i18n);
Expand All @@ -28,5 +28,3 @@ const install = (app, options = {}) => {
});
});
};

export { install };
4 changes: 4 additions & 0 deletions src/install.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ describe('install', () => {
dSpy = jest.spyOn(app, 'directive');
});

it('should have install function', async () => {
expect(uiv.install).toEqual(expect.any(Function));
});

it('should be able to install with prefix', () => {
// simulate a Vue.use
app.use(uiv, { prefix: 'uiv' });
Expand Down
8 changes: 4 additions & 4 deletions src/utils/string.utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function pad(value, num) {
value = value + '';
for (let i = num - value.length; i > 0; i--) {
value = '0' + value;
let res = value.toString();
for (let i = num - res.length; i > 0; i--) {
res = '0' + res;
}
return value;
return res;
}
15 changes: 15 additions & 0 deletions src/utils/string.utils.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as utils from './string.utils';

describe('string.utils', () => {
describe('#pad ', () => {
it('should be able to pad string', () => {
expect(utils.pad('1', 2)).toEqual('01');
expect(utils.pad('01', 2)).toEqual('01');
expect(utils.pad('001', 2)).toEqual('001');
});

it('should be able to pad non string', () => {
expect(utils.pad(100, 5)).toEqual('00100');
});
});
});

0 comments on commit b452445

Please sign in to comment.