Skip to content
This repository has been archived by the owner on Aug 25, 2020. It is now read-only.

Commit

Permalink
bugfix: generate default label of value as an object
Browse files Browse the repository at this point in the history
when object passed as value to form key and the label property was not assigned, the label was not generated automatically
  • Loading branch information
Nevoss committed Oct 30, 2018
1 parent bc0047a commit 7ab0706
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/core/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,10 @@ export class Form {
if (data[key].hasOwnProperty('label')) {
labels[key] = data[key].label
}

return
}

labels[key] = key in labels ? labels[key] : generateDefaultLabel(key)
originalData[key] = data[key]
originalData[key] = key in originalData ? originalData[key] : data[key]
})

this.$originalData = originalData
Expand Down
14 changes: 10 additions & 4 deletions tests/core/Form.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,22 @@ describe('Form.js', () => {
label: 'Name',
rules: rulesArray,
},
last_name: 'Golan'
last_name: 'Golan',
is_developer: {
value: false,
},
})

expect(form.name).toBe('Nevo')
expect(form.last_name).toBe('Golan')
expect(generateDefaultLabel.mock.calls).toHaveLength(1)
expect(generateDefaultLabel).toBeCalledWith('last_name')
expect(form.is_developer).toBe(false)
expect(generateDefaultLabel.mock.calls).toHaveLength(2)
expect(generateDefaultLabel.mock.calls[0][0]).toEqual('last_name')
expect(generateDefaultLabel.mock.calls[1][0]).toEqual('is_developer')
expect(form.$labels).toEqual({
name: 'Name',
last_name: 'a'
last_name: 'a',
is_developer: 'a',
})
expect(Validator).toHaveBeenCalledWith({name: rulesArray}, defaultOptions.validation)
expect(Errors).toHaveBeenCalled()
Expand Down

0 comments on commit 7ab0706

Please sign in to comment.