Created
January 27, 2018 17:18
-
-
Save ramon-src/7ad888d195c83dcd45496545d40d27d9 to your computer and use it in GitHub Desktop.
Refactoring mocking axios lib and creating a beforeAll method to mock axios in all tests with shallow, because mount is not necessary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { shallow } from 'vue-test-utils'; | |
import ServicePage from '@/components/Service'; | |
const axios = { | |
get: (url) => { | |
if (url === '/') { | |
return Promise.resolve({ | |
data: [ | |
{ name: 'Ramon', status: 'true' }, | |
{ name: 'Rodrigo', status: 'true' }, | |
], | |
}); | |
} | |
return Promise.reject(); | |
}, | |
}; | |
describe('ServicePage', () => { | |
let servicePage; | |
beforeAll(() => { | |
servicePage = shallow(ServicePage, { | |
mocks: { | |
axios, | |
}, | |
}); | |
}); | |
it('should show the state from service', () => { | |
expect(servicePage.find('.service__list-item-status').text()).toBe('true'); | |
}); | |
it('should show the name from service', () => { | |
expect(servicePage.find('.service__list-item-name').text()).toBe('Ramon'); | |
}); | |
it('should service list has two services after request services', () => { | |
const twoServices = [{ name: 'Ramon', status: 'true' }, { name: 'Rodrigo', status: 'true' }]; | |
servicePage.vm.$nextTick(() => { | |
expect(servicePage.vm.services).toEqual(twoServices); | |
}); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment