test: refs #7100 added test to vnNotes component #1121
|
@ -4,21 +4,23 @@ import VnNotes from 'src/components/ui/VnNotes.vue';
|
|||
|
||||
describe('VnNotes', () => {
|
||||
let vm;
|
||||
let wrapper;
|
||||
let spyFetch;
|
||||
let postMock;
|
||||
let expectedBody;
|
||||
|
||||
beforeAll(async () => {
|
||||
vi.spyOn(axios, 'get').mockReturnValue({ data: [] });
|
||||
|
||||
vm = createWrapper(VnNotes, {
|
||||
wrapper = createWrapper(VnNotes, {
|
||||
propsData: {
|
||||
url: '/test',
|
||||
filter: { order: 'created DESC' },
|
||||
body: { name: 'Tony', lastName: 'Stark' },
|
||||
addNote: false,
|
||||
selectType: true,
|
||||
selectType: false,
|
||||
|
||||
}
|
||||
}).vm;
|
||||
});
|
||||
wrapper = wrapper.wrapper;
|
||||
vm = wrapper.vm;
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -31,9 +33,10 @@ describe('VnNotes', () => {
|
|||
});
|
||||
|
||||
describe('insert', () => {
|
||||
jsegarra marked this conversation as resolved
Outdated
jsegarra
commented
Este caso no se dará, está bien incluirlo, pero para ser completo el test deberíamos probar con null Este caso no se dará, está bien incluirlo, pero para ser completo el test deberíamos probar con null
|
||||
it('should not call axios.post if newNote.text is empty', async () => {
|
||||
vm.newNote.text = '';
|
||||
vm.newNote.observationTypeFk = 1;
|
||||
it('should not call axios.post and vnPaginateRef.fetch if newNote.text is null', async () => {
|
||||
vm.newNote.text = null;
|
||||
vm.newNote.observationTypeFk = null;
|
||||
await wrapper.setProps({ selectType: true });
|
||||
jsegarra marked this conversation as resolved
Outdated
jsegarra
commented
porque usas await? porque usas await?
jtubau
commented
Para asegurar que selectType haya cambiado correctamente antes de continuar, ya que si no lo uso, se ejecuta vm.insert() antes de que se actualice el valor y el test falla, lo mismo con el vm.insert, ya que los expect se ejecutan antes de que sus correspondientes métodos espiados sean ejecutados. Para asegurar que selectType haya cambiado correctamente antes de continuar, ya que si no lo uso, se ejecuta vm.insert() antes de que se actualice el valor y el test falla, lo mismo con el vm.insert, ya que los expect se ejecutan antes de que sus correspondientes métodos espiados sean ejecutados.
jsegarra
commented
Estoy mirando la documentación y devuelve una promesa, https://test-utils.vuejs.org/api/#setProps Estoy mirando la documentación y devuelve una promesa, https://test-utils.vuejs.org/api/#setProps
Cuando puse el comentario no vi el await
|
||||
|
||||
await vm.insert();
|
||||
|
||||
|
@ -41,9 +44,10 @@ describe('VnNotes', () => {
|
|||
expect(spyFetch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not call axios.post if observationTypeFk is missing and selectType is set', async () => {
|
||||
vm.newNote.text = 'Test Note';
|
||||
it('should not call axios.post and vnPaginateRef.fetch if newNote.text is empty', async () => {
|
||||
vm.newNote.text = "";
|
||||
vm.newNote.observationTypeFk = null;
|
||||
await wrapper.setProps({ selectType: false });
|
||||
|
||||
await vm.insert();
|
||||
|
||||
|
@ -51,11 +55,49 @@ describe('VnNotes', () => {
|
|||
expect(spyFetch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not call axios.post and vnPaginateRef.fetch if observationTypeFk is missing and selectType is true', async () => {
|
||||
vm.newNote.text = 'Test Note';
|
||||
vm.newNote.observationTypeFk = null;
|
||||
await wrapper.setProps({ selectType: true });
|
||||
|
||||
await vm.insert();
|
||||
|
||||
expect(postMock).not.toHaveBeenCalled();
|
||||
expect(spyFetch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call axios.post and vnPaginateRef.fetch if observationTypeFk is missing and selectType is false', async () => {
|
||||
vm.newNote.text = "Test Note";
|
||||
vm.newNote.observationTypeFk = null;
|
||||
await wrapper.setProps({ selectType: false });
|
||||
|
||||
expectedBody = {...vm.$props.body, ...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk }};
|
||||
|
||||
await vm.insert();
|
||||
|
||||
expect(postMock).toHaveBeenCalledWith(vm.$props.url, expectedBody);
|
||||
expect(spyFetch).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call axios.post and vnPaginateRef.fetch if observationTypeFk is setted and selectType is false', async () => {
|
||||
vm.newNote.text = "Test Note";
|
||||
vm.newNote.observationTypeFk = 1;
|
||||
await wrapper.setProps({ selectType: false });
|
||||
|
||||
expectedBody = {...vm.$props.body, ...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk }};
|
||||
|
||||
await vm.insert();
|
||||
|
||||
expect(postMock).toHaveBeenCalledWith(vm.$props.url, expectedBody);
|
||||
expect(spyFetch).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call axios.post and vnPaginateRef.fetch when newNote is valid', async () => {
|
||||
vm.newNote.text = 'Test Note';
|
||||
vm.newNote.observationTypeFk = 1;
|
||||
wrapper.setProps({ selectType: false });
|
||||
|
||||
const expectedBody = {...vm.$props.body, ...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk }};
|
||||
expectedBody = {...vm.$props.body, ...{ text: vm.newNote.text, observationTypeFk: vm.newNote.observationTypeFk }};
|
||||
|
||||
await vm.insert();
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Todos los test asument que selectType es true, que pasa cuando le damos valor false?
Falla