I test my Vue.js project with Jest test tool. For only the coverage, I wish to test top level .js, too. It passed, but I got the error message below.
How do you test top level .js?
console.error node_modules\vue\dist\vue.runtime.common.js:589
[Vue warn]: Cannot find element: #app
console.error node_modules\vue\dist\vue.runtime.common.js:589
[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.
(found in <Root>)
My main.js:
import Vue from 'vue'
import App from '@/App'
import store from '@/store'
import router from '@/router'
/* eslint-disable no-new */
new Vue({
el: '#app',
store,
router,
components: { App },
template: '<App/>',
})
My main.spec.js:
import main from '@/main'
describe('main.js', () => {
beforeEach(() => {
jest.spyOn(console, 'log')
jest.spyOn(console, 'error')
})
afterEach(() => {
console.log.mockRestore()
console.error.mockRestore()
})
it('init', () => {
expect(console.log).not.toHaveBeenCalled()
expect(console.error).not.toHaveBeenCalled()
})
})