Skip to content

Commit c77c58a

Browse files
committed
test: update test
1 parent dbfeaaa commit c77c58a

File tree

3 files changed

+89
-72
lines changed

3 files changed

+89
-72
lines changed

test/component.test.js

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,55 @@ import JsonEditorSrc from '@/JsonEditor.vue';
66
const JsonEditor = process.env.TEST_LIB ? JsonEditorLib : JsonEditorSrc;
77

88
describe('JsonEditor', () => {
9-
it('should have a created hook', () => {
10-
expect(typeof JsonEditor.created).toBe('function');
11-
});
129

13-
it('should have a mounted hook', () => {
14-
expect(typeof JsonEditor.mounted).toBe('function');
15-
});
10+
describe('hook', () => {
11+
it('should have a created hook', () => {
12+
expect(typeof JsonEditor.created).toBe('function');
13+
});
1614

17-
it('should have a changed method', () => {
18-
expect(typeof JsonEditor.methods.changed).toBe('function');
15+
it('should have a mounted hook', () => {
16+
expect(typeof JsonEditor.mounted).toBe('function');
17+
});
1918
});
2019

21-
it('should have a input method', () => {
22-
expect(typeof JsonEditor.methods.input).toBe('function');
23-
});
20+
describe('method', () => {
21+
it('should have a changed method', () => {
22+
expect(typeof JsonEditor.methods.changed).toBe('function');
23+
});
2424

25-
it('should have a reset method', () => {
26-
expect(typeof JsonEditor.methods.reset).toBe('function');
27-
});
25+
it('should have a input method', () => {
26+
expect(typeof JsonEditor.methods.input).toBe('function');
27+
});
2828

29-
it('should have a submit method', () => {
30-
expect(typeof JsonEditor.methods.submit).toBe('function');
31-
});
29+
it('should have a reset method', () => {
30+
expect(typeof JsonEditor.methods.reset).toBe('function');
31+
});
3232

33-
it('should have a setErrorMessage method', () => {
34-
expect(typeof JsonEditor.methods.setErrorMessage).toBe('function');
35-
});
33+
it('should have a submit method', () => {
34+
expect(typeof JsonEditor.methods.submit).toBe('function');
35+
});
36+
37+
it('should have a setErrorMessage method', () => {
38+
expect(typeof JsonEditor.methods.setErrorMessage).toBe('function');
39+
});
3640

37-
it('should have a clearErrorMessage method', () => {
38-
expect(typeof JsonEditor.methods.clearErrorMessage).toBe('function');
41+
it('should have a clearErrorMessage method', () => {
42+
expect(typeof JsonEditor.methods.clearErrorMessage).toBe('function');
43+
});
3944
});
4045

41-
// Evaluate the results of functions in
42-
// the raw component options
43-
it('should set the correct default data', () => {
44-
expect(typeof JsonEditor.data).toBe('function');
45-
const defaultData = JsonEditor.data();
46+
describe('data', () => {
47+
// Evaluate the results of functions in
48+
// the raw component options
49+
it('should set the correct default data', () => {
50+
expect(typeof JsonEditor.data).toBe('function');
51+
const defaultData = JsonEditor.data();
4652

47-
expect(Object.keys(defaultData.default).length).toBe(0);
48-
// expect(defaultData.fields.length).toBe(0);
49-
expect(defaultData.error).toBe(null);
53+
expect(Object.keys(defaultData.default).length).toBe(0);
54+
// expect(defaultData.fields.length).toBe(0);
55+
expect(defaultData.error).toBe(null);
56+
});
5057
});
58+
59+
5160
});

test/schema.test.js

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,50 +22,54 @@ describe('schema', () => {
2222

2323
const attr = (input, name) => input.getAttribute(name);
2424

25-
for (const fieldName in schema.properties) {
26-
const field = schema.properties[fieldName];
27-
28-
if (field.visible === false) {
29-
it(`invisible input.${ fieldName } should be undefined`, () => {
30-
expect(inputs[fieldName]).toBe(undefined);
31-
});
32-
continue;
33-
}
25+
describe('input', () => {
26+
for (const fieldName in schema.properties) {
27+
const field = schema.properties[fieldName];
28+
29+
if (field.visible === false) {
30+
it(`invisible input.${ fieldName } should be undefined`, () => {
31+
expect(inputs[fieldName]).toBe(undefined);
32+
});
33+
continue;
34+
}
3435

35-
const input = inputs[fieldName];
36+
const input = inputs[fieldName];
3637

37-
if (!field.attrs) {
38-
field.attrs = {};
39-
}
38+
if (!field.attrs) {
39+
field.attrs = {};
40+
}
4041

41-
field.attrs.name = fieldName;
42+
field.attrs.name = fieldName;
4243

43-
if (field.type === 'boolean') {
44-
field.attrs.type = 'checkbox';
45-
}
44+
if (field.type === 'boolean') {
45+
field.attrs.type = 'checkbox';
46+
}
4647

47-
if (field.minLength) {
48-
field.attrs.minlength = field.minLength;
49-
}
48+
if (field.minLength) {
49+
field.attrs.minlength = field.minLength;
50+
}
5051

51-
if (field.maxLength) {
52-
field.attrs.maxlength = field.maxLength;
53-
}
52+
if (field.maxLength) {
53+
field.attrs.maxlength = field.maxLength;
54+
}
5455

55-
if (field.required) {
56-
field.attrs.required = true;
56+
if (field.required) {
57+
field.attrs.required = true;
5758

58-
if (field.attrs.placeholder) {
59-
field.attrs.placeholder += ' *';
59+
if (field.attrs.placeholder) {
60+
field.attrs.placeholder += ' *';
61+
}
6062
}
61-
}
6263

63-
for (const attrName in field.attrs) {
64-
it(`input.${ fieldName } should have attribute '${ attrName }'`, () => {
65-
expect(attr(input, attrName)).toMatch(new RegExp(`${ field.attrs[attrName] }`));
64+
describe(fieldName, () => {
65+
for (const attrName in field.attrs) {
66+
it(`should have attribute '${ attrName }'`, () => {
67+
expect(attr(input, attrName)).toMatch(new RegExp(`${ field.attrs[attrName] }`));
68+
});
69+
}
6670
});
6771
}
68-
}
72+
});
6973

7074
it('should have a submit button', () => {
7175
expect(attr(button, 'type')).toBe('submit');

test/simple.test.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ const model2 = {
1818
};
1919

2020
describe('Component', () => {
21-
test('Mount', () => {
21+
it('Mount', () => {
2222
const wrapper = shallow(JsonEditor, {
2323
propsData: { schema },
2424
});
2525
expect(wrapper.isVueInstance()).toBeTruthy();
2626
});
2727

28-
test('Snapshot', done => {
28+
it('Snapshot', done => {
2929
const wrapper = shallow(JsonEditor, {
3030
propsData: { schema },
3131
});
@@ -37,21 +37,25 @@ describe('Component', () => {
3737
});
3838
});
3939

40-
test('Mount with data and set data', () => {
40+
describe('Mount with data and set data', () => {
4141
const wrapper = shallow(JsonEditor, {
4242
propsData: { schema, value: model },
4343
});
4444
const component = wrapper.vm;
4545
expect(wrapper.isVueInstance()).toBeTruthy();
4646
const form = component.$el.getElementsByTagName('form')[0];
4747
const { name, lists, email } = form.elements;
48-
// get mounted data
49-
expect(name.getAttribute('value')).toBe(model.name);
50-
expect(lists.getAttribute('value')).toBe(model.lists[0]);
51-
// update value by setData
52-
wrapper.setData({ value: model2 });
53-
expect(email.getAttribute('value')).toBe(model2.email);
54-
expect(name.getAttribute('value')).toBe(model2.name);
48+
49+
it('get mounted data', () => {
50+
expect(name.getAttribute('value')).toBe(model.name);
51+
expect(lists.getAttribute('value')).toBe(model.lists[0]);
52+
});
53+
54+
it('update value by setData', () => {
55+
wrapper.setData({ value: model2 });
56+
expect(email.getAttribute('value')).toBe(model2.email);
57+
expect(name.getAttribute('value')).toBe(model2.name);
58+
});
5559
});
5660

5761
});

0 commit comments

Comments
 (0)