Answer the question
In order to leave comments, you need to log in
Validated value testing?
Hello. Tell me please. I still can’t write a test in Jest to check a valid value. The VeeValidate plugin is used, I found an official example , but it doesn't seem to work.
import { createLocalVue, shallow } from '@vue/test-utils';
import flushPromises from 'flush-promises';
import VeeValidate from 'vee-validate';
import Vuetify from 'vuetify';
import SignUp from './../../src/views/SignUp.vue';
const localVue = createLocalVue( );
localVue.use( VeeValidate );
localVue.use( Vuetify );
describe( 'SignUp', ( ) => {
it( 'should invalid field username length less 5', async ( ) => {
const wrapper = shallow( SignUp, { localVue } );
expect( wrapper.vm.errors.count( ) ).toBe( 0 );
wrapper.setData( { username: 'asdf' } );
await flushPromises( );
expect( wrapper.vm.errors.has( 'username' ) ).toBe( true );
} );
FAIL tests\unit\SignUp.spec.js
SignUp
× should invalid field username length less 5 (44ms)
● SignUp › should invalid field username length less 5
expect(received).toBe(expected) // Object.is equality
Expected value to be:
true
Received:
false
18 | // await wrapper.vm.$validator.validateAll( );
19 | await flushPromises( );
> 20 | await expect( wrapper.vm.errors.has( 'username' ) ).toBe( true );
21 | } );
22 |
23 |
at Object._callee$ (tests/unit/SignUp.spec.js:20:57)
at tryCatch (node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:296:22)
at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:114:21)
at step (node_modules/@babel/runtime/helpers/asyncToGenerator.js:12:30)
at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:27:9)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 3.971s
Ran all test suites.
ERROR jest exited with code 1.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question