Skip to content

Commit

Permalink
🐛 HDResponsive to properly run on SSR (#844)
Browse files Browse the repository at this point in the history
* 🐛 HDResponsive to use window on mounted

* 📸 snapshot update

* ✏️ typo

* ✅ removed not suiting test

* ✅ fixed tests

* ✏️ typo and lint
  • Loading branch information
drapisarda authored Oct 19, 2021
1 parent 38d7d98 commit 9a6f0b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/components/HdResponsive.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ export default {
this.setListeners();
},
},
created() {
mounted() {
this.setListeners();
this.$forceUpdate();
},
methods: {
/* istanbul ignore next */
Expand Down
14 changes: 11 additions & 3 deletions tests/unit/components/HdResponsive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('HdResponsive', () => {
expect(wrapper.html()).toMatchSnapshot();
});

it('provides "matches" object as part of a scoped slot', () => {
it('provides "matches" object as part of a scoped slot', async () => {
setBreakpoints(BREAKPOINTS);

const wrapper = wrapperBuilder({
Expand All @@ -47,6 +47,8 @@ describe('HdResponsive', () => {
},
});

await wrapper.vm.$nextTick();

expect(wrapper.html()).toMatchSnapshot();
});

Expand All @@ -62,7 +64,7 @@ describe('HdResponsive', () => {
expect(wrapper.html()).toMatchSnapshot();
});

it('breakpoint changes are managed', () => {
it('breakpoints set and change are managed', async () => {
setBreakpoints(BREAKPOINTS);

const mockedSetListeners = jest.fn();
Expand All @@ -77,11 +79,17 @@ describe('HdResponsive', () => {
},
});

// first at the mount...
expect(mockedSetListeners).toHaveBeenCalledTimes(1);

const modifiedBreakpoints = BREAKPOINTS;
delete modifiedBreakpoints.s;

wrapper.setProps({ breakpoints: modifiedBreakpoints });

expect(mockedSetListeners).toHaveBeenCalled();
await wrapper.vm.$nextTick();

// ...then by the watch
expect(mockedSetListeners).toHaveBeenCalledTimes(2);
});
});

0 comments on commit 9a6f0b4

Please sign in to comment.