Skip to content

Commit

Permalink
Add test for hmr option
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsn committed Mar 11, 2017
1 parent 0acb10b commit aababef
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions test/template-loader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function mockRender (options, data = {}) {
return options.render.call(Object.assign(mock, data))
}

function loadCode(data, { style, query = '' } = {}) {
function loadCode(data, { style, query = {}} = {}) {
return loader.call({
cacheable: () => {},
options: {},
Expand Down Expand Up @@ -95,10 +95,22 @@ describe('vue-template-loader', () => {
})

it('inject scoped id and scoped css', () => {
const code = loadCode('<div>hi</div>', { style: './style.css', query: '?scoped' })
const code = loadCode('<div>hi</div>', { style: './style.css', query: { scoped: true }})
expect(code).toMatch(/options\._scopeId = 'data-v-[^']+'/)
expect(code).toMatch(
/require\('[^!?]*scoped-style-loader\.js\?id=[^!]+!\.\/style\.css'\)/
)
})

it('has the code for HMR', () => {
const code = loadCode('<div>hi</div>')
expect(code).toMatch('vue-hot-reload-api')
expect(code).toMatch('module.hot')
})

it('disable HMR by option', () => {
const code = loadCode('<div>hi</div>', { query: { hmr: false }})
expect(code).not.toMatch('vue-hot-reload-api')
expect(code).not.toMatch('module.hot')
})
})

0 comments on commit aababef

Please sign in to comment.