Skip to content

Commit b452445

Browse files
committed
test: add test for string utils
1 parent 3acfda0 commit b452445

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

src/install.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as directives from './directives';
33
import * as services from './services';
44
import locale from './locale';
55

6-
const install = (app, options = {}) => {
6+
export const install = (app, options = {}) => {
77
// Setup language, en-US for default
88
locale.use(options.locale);
99
locale.i18n(options.i18n);
@@ -28,5 +28,3 @@ const install = (app, options = {}) => {
2828
});
2929
});
3030
};
31-
32-
export { install };

src/install.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ describe('install', () => {
1111
dSpy = jest.spyOn(app, 'directive');
1212
});
1313

14+
it('should have install function', async () => {
15+
expect(uiv.install).toEqual(expect.any(Function));
16+
});
17+
1418
it('should be able to install with prefix', () => {
1519
// simulate a Vue.use
1620
app.use(uiv, { prefix: 'uiv' });

src/utils/string.utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export function pad(value, num) {
2-
value = value + '';
3-
for (let i = num - value.length; i > 0; i--) {
4-
value = '0' + value;
2+
let res = value.toString();
3+
for (let i = num - res.length; i > 0; i--) {
4+
res = '0' + res;
55
}
6-
return value;
6+
return res;
77
}

src/utils/string.utils.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as utils from './string.utils';
2+
3+
describe('string.utils', () => {
4+
describe('#pad ', () => {
5+
it('should be able to pad string', () => {
6+
expect(utils.pad('1', 2)).toEqual('01');
7+
expect(utils.pad('01', 2)).toEqual('01');
8+
expect(utils.pad('001', 2)).toEqual('001');
9+
});
10+
11+
it('should be able to pad non string', () => {
12+
expect(utils.pad(100, 5)).toEqual('00100');
13+
});
14+
});
15+
});

0 commit comments

Comments
 (0)