Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit ad75b2e

Browse files
committed
Use a real Vuex Store with mock dispatch for Language Picker spec.
1 parent 2c2beac commit ad75b2e

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

test/unit/specs/locale/cd-lang-picker.spec.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import vueUnitHelper from 'vue-unit-helper';
22
import LangPicker from '!!vue-loader?inject!@/locale/cd-lang-picker';
33
import { expect } from 'chai';
4+
import Vuex from 'vuex';
45

56
describe('Lang Picker', () => {
67
let CookieMock;
78
let LocaleServiceMock;
89
let MomentMock;
910
let LangPickerWithMocks;
10-
let StoreMock;
11+
const StoreMock = new Vuex.Store()
1112

1213
beforeEach(() => {
1314
CookieMock = {
@@ -26,9 +27,7 @@ describe('Lang Picker', () => {
2627
moment: MomentMock,
2728
});
2829

29-
StoreMock = {
30-
dispatch: sinon.stub(),
31-
};
30+
StoreMock.dispatch = sinon.stub();
3231
});
3332

3433
afterEach(() => {
@@ -96,7 +95,7 @@ describe('Lang Picker', () => {
9695
foo: 'foo',
9796
});
9897
expect(vm.$i18n.locale).to.equal('es_ES');
99-
expect(StoreMock.dispatch.calledOnce).to.eq(true);
98+
expect(StoreMock.dispatch).to.have.been.calledWith('updateChosenLanguageConfig');
10099
done();
101100
});
102101
});
@@ -130,7 +129,7 @@ describe('Lang Picker', () => {
130129

131130
// ASSERT
132131
expect(vm.lang).to.equal('es_ES');
133-
expect(StoreMock.dispatch.calledOnce).to.eq(true);
132+
expect(StoreMock.dispatch).to.have.been.calledWith('updateChosenLanguageConfig');
134133
});
135134

136135
it('should set lang to the browser locale if no cookie, and locale matches an available one', async () => {
@@ -146,7 +145,7 @@ describe('Lang Picker', () => {
146145

147146
// ASSERT
148147
expect(vm.lang).to.equal('it_IT');
149-
expect(StoreMock.dispatch.calledOnce).to.eq(true);
148+
expect(StoreMock.dispatch).to.have.been.calledWith('updateChosenLanguageConfig');
150149
});
151150

152151
it('should set lang to en_US if no cookie and browser locale doesnt match available lang', async () => {
@@ -162,7 +161,7 @@ describe('Lang Picker', () => {
162161

163162
// ASSERT
164163
expect(vm.lang).to.equal('en_US');
165-
expect(StoreMock.dispatch.calledOnce).to.eq(true);
164+
expect(StoreMock.dispatch).to.have.been.calledWith('updateChosenLanguageConfig');
166165
});
167166
});
168167
});

0 commit comments

Comments
 (0)