Skip to content

Commit af0638a

Browse files
author
Rija Menage
committed
Refine UX: error is accounted for but not displayed if username is empty
because it will irritate the user to get the error on the onset. Implementing this exposed the issue fixed in the previous commit where the test for too short username was picking up the wrong state of the component (testing against the initial value of username which was empty string instead of the updated value after setting up the test username). In the test here we use the Truthy test for the computed property 'error' because it's not true as in the boolean type, it's a non-empty string which count as "truthy". For testing the display of the .error div, we use the absolute boolean test, because exists() returns either true or false as in the boolean types.
1 parent bdd9112 commit af0638a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/components/UserNameComponent.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div>
33
<label class="form-label" for="username-field">{{ fullPrompt }}</label>
44
<input id="username-field" v-model="username" />
5-
<div v-if="error" class="error">
5+
<div v-if="error && username!==''" class="error">
66
{{ error }}
77
</div>
88
</div>

test/UserNameComponent.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,14 @@ describe('Username component', function () {
7171
expect(wrapper.find('.error').exists()).toBeFalse()
7272
})
7373
})
74+
75+
it('returns an error but does not display it if username is empty', function() {
76+
const wrapper = factory({
77+
prompt: 'foo bar',
78+
username: '',
79+
minLength: 4,
80+
})
81+
expect(wrapper.vm.error).toBeTruthy()
82+
expect(wrapper.find('.error').exists()).toBeFalse()
83+
})
7484
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy