Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pirhoo committed Mar 20, 2020
1 parent 2a063cd commit ba4ff45
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/components/WidgetCreationDateOverTime.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ export default {
}
},
mounted () {
this.$nextTick(() => {
this.mounted = true
this.init()
})
this.$nextTick(() => this.init())
},
computed: {
...mapState('search', ['index']),
Expand Down Expand Up @@ -129,10 +126,10 @@ export default {
},
async init () {
this.data = await this.loadData()
this.mounted = true
// Build the chart when its container is resized
const observer = new ResizeObserver(this.buildChart)
observer.observe(this.container)
this.buildChart()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@ describe('WidgetCreationDateOverTime.vue', () => {
const propsData = { widget }
const index = toLower('WidgetCreationDateOverTime')
const anotherIndex = toLower('anotherIndex')
const methods = { loadData: () => [{ date: new Date('2012-02'), doc_count: 2 }, { date: new Date('2012-03'), doc_count: 4 }] }
esConnectionHelper([index, anotherIndex])
const es = esConnectionHelper.es

beforeAll(() => store.commit('search/index', index))

it('should be a Vue instance', () => {
const wrapper = shallowMount(WidgetCreationDateOverTime, { i18n, localVue, propsData, store, wait })
const wrapper = shallowMount(WidgetCreationDateOverTime, { i18n, localVue, methods, propsData, store, wait })
expect(wrapper.isVueInstance()).toBeTruthy()
})

it('should display a barchart with 2 bars', async () => {
const methods = { loadData: () => [{ date: new Date('2012-02'), doc_count: 2 }, { date: new Date('2012-03'), doc_count: 4 }] }
const wrapper = mount(WidgetCreationDateOverTime, { i18n, localVue, methods, propsData, store, wait, attachToDocument: true })
await wrapper.vm.$nextTick()

expect(wrapper.findAll('svg')).toHaveLength(1)
expect(wrapper.findAll('svg rect')).toHaveLength(2)
})
Expand All @@ -46,7 +45,7 @@ describe('WidgetCreationDateOverTime.vue', () => {
})

it('should rerun init on index change', async () => {
const wrapper = mount(WidgetCreationDateOverTime, { i18n, localVue, propsData, store, wait, attachToDocument: true })
const wrapper = mount(WidgetCreationDateOverTime, { i18n, localVue, methods, propsData, store, wait, attachToDocument: true })
const init = jest.spyOn(wrapper.vm, 'init')
await wrapper.vm.$nextTick()
expect(init).toBeCalledTimes(1)
Expand Down

0 comments on commit ba4ff45

Please sign in to comment.