Closed ciemarr closed 5 years ago
I still don't know what the problem with the IntersectionObserver polyfill in tests is, but I am able to ignore it for now by passing a second parameter into shallowMount
to mock out the resize
directive:
var mockDirective = {};
shallowMount(HelloWorld, { directives: { resize: mockDirective } });
I was reading your first post before seeing your second comment, and I was thinking exatly the same thing that you suggest before. For test purpose a mock directive should do the trick.
There seems to be a problem with some combination of Vue, Webpack, Mocha, vue-resize-directive, and the intersection-observer polyfill. (I've cross-posted this question to the Vue community more broadly, too.)
The
v-resize
directive does work just fine in a real browser. It's only the test that is failing to find the definition ofIntersectionObserver
.Repro Steps
I created a new Vue project:
vue create vue-resize-directive-test
yarn test:unit
on generated example code passesThen I added the
v-resize
directive:yarn add vue-resize-directive
typings/vue-resize-directive.d.ts
:tsconfig.json
to include the definition:WEBPACK Compiled successfully in 13052ms
MOCHA Testing...
HelloWorld.vue [Vue warn]: Error in directive resize inserted hook: "ReferenceError: IntersectionObserver is not defined"
found in
---> at src/components/HelloWorld.vue